Skip to content

Commit 2e29b15

Browse files
committed
initial commit
0 parents  commit 2e29b15

12 files changed

+509
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/nbproject
2+
/t/servroot

.idea/misc.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/ngx_immutable.iml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

+65
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.travis.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
language: c
2+
compiler:
3+
- clang
4+
- gcc
5+
env:
6+
matrix:
7+
- NGINX_VERSION=1.16.1
8+
- NGINX_VERSION=1.17.8
9+
addons:
10+
apt:
11+
packages:
12+
- libpcre3-dev
13+
- libssl-dev
14+
- perl
15+
- cpanminus
16+
cache:
17+
ccache: true
18+
directories:
19+
- $HOME/perl5
20+
before_install:
21+
- test $TRAVIS_BRANCH != coverity_scan -o ${TRAVIS_JOB_NUMBER##*.} = 1 || exit 0
22+
- cpanm --notest --local-lib=$HOME/perl5 Test::Nginx
23+
install:
24+
- test $TRAVIS_BRANCH != coverity_scan || exit 0
25+
- wget -O - http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz | tar -xzf -
26+
- cd nginx-${NGINX_VERSION}
27+
- ./configure --with-debug --add-module=..
28+
- make -j2
29+
- export PATH=$(pwd)/objs:$PATH
30+
- cd ..
31+
script:
32+
- test $TRAVIS_BRANCH != coverity_scan || exit 0
33+
- PERL5LIB=$HOME/perl5/lib/perl5 TEST_NGINX_VERBOSE=true prove -v
34+
after_failure:
35+
- cat t/servroot/conf/nginx.conf
36+
- cat t/servroot/access.log
37+
- cat t/servroot/error.log

LICENSE

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (C) 2019-2020 Danila Vershinin
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
* 1. Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24+
* SUCH DAMAGE.
25+
*/

README.md

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# ngx_immutable
2+
3+
[![Build Status](https://travis-ci.org/GetPageSpeed/ngx_immutable.svg?branch=master)](https://travis-ci.org/GetPageSpeed/ngx_immutable)
4+
[![Coverity Scan](https://img.shields.io/coverity/scan/GetPageSpeed-ngx_immutable)](https://scan.coverity.com/projects/GetPageSpeed-ngx_immutable)
5+
6+
This tiny NGINX module can help improve caching of your public static assets, by setting far future expiration with `immutable` attribute.
7+
8+
## Synopsis
9+
10+
```
11+
http {
12+
server {
13+
location /static/ {
14+
immutable on;
15+
}
16+
}
17+
}
18+
```
19+
20+
will yield the following HTTP headers:
21+
22+
```
23+
...
24+
Cache-Control: public,max-age=31536000,immutable
25+
Expires: Thu, 31 Dec 2037 23:55:55 GMT
26+
...
27+
```
28+
29+
How it's different to `expires max;`:
30+
31+
* Sets `immutable` attribute, e.g. `Cache-Control: public,max-age=31536000,immutable` for improved caching
32+
* Sends `Expires` only when it's really necessary, e.g. when a client is requesting resources over `HTTP/1.0`
33+
* Sets `public` attribute to ensure the assets can be cached by public caches, which is typically a desired thing.
34+
35+
Thus in most cases, `immutable on;` can be used as as a better alternative to `expires max;`.
36+
37+
## Installation
38+
39+
### CentOS/RHEL 6, 7, 8
40+
41+
sudo yum -y install https://extras.getpagespeed.com/release-latest.rpm
42+
sudo yum -y install nginx-module-immutable
43+
44+
Follow the installation prompt to import GPG public key that is used for verifying packages.
45+
46+
Then add the following at the top of your `/etc/nginx/nginx.conf`:
47+
48+
load_module modules/ngx_http_immutable_module.so;
49+
50+
## Example: Magento 2 production configuration
51+
52+
Provided that your store runs in production mode, you have already compiled all the assets.
53+
This [sample config](https://github.com/magento/magento2/blob/2.3.4/nginx.conf.sample#L103-L134) can be optimized to:
54+
55+
```
56+
location /static/ {
57+
immutable on;
58+
59+
# Remove signature of the static files that is used to overcome the browser cache
60+
location ~ ^/static/version {
61+
rewrite ^/static/(version\d*/)?(.*)$ /static/$2 last;
62+
}
63+
64+
location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2|json)$ {
65+
add_header X-Frame-Options "SAMEORIGIN";
66+
}
67+
location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
68+
add_header Cache-Control "no-store";
69+
add_header X-Frame-Options "SAMEORIGIN";
70+
immutable off;
71+
}
72+
add_header X-Frame-Options "SAMEORIGIN";
73+
}
74+
```
75+
76+
When used together with `ngx_security_headers`, it can be simplified further:
77+
78+
```
79+
security_headers on;
80+
81+
location /static/ {
82+
immutable on;
83+
84+
85+
location ~ ^/static/version {
86+
rewrite ^/static/(version\d*/)?(.*)$ /static/$2 last;
87+
}
88+
89+
location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
90+
add_header Cache-Control "no-store";
91+
immutable off;
92+
}
93+
}
94+
```

config

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
ngx_addon_name=ngx_http_immutable_module
2+
3+
if test -n "$ngx_module_link"; then
4+
ngx_module_type=HTTP_AUX_FILTER
5+
ngx_module_name=ngx_http_immutable_module
6+
ngx_module_srcs="$ngx_addon_dir/src/ngx_http_immutable.c"
7+
8+
. auto/module
9+
else
10+
HTTP_AUX_FILTER_MODULES="$HTTP_AUX_FILTER_MODULES ngx_http_immutable_module"
11+
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/src/ngx_http_immutable.c"
12+
fi

0 commit comments

Comments
 (0)