Skip to content

Commit fb8366d

Browse files
committed
Rename files, add cloudflare and webp support
1 parent c8e8705 commit fb8366d

15 files changed

+157
-39
lines changed

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ There are multiplpe advantages of using this repo as your go-to nginx configurat
1111
+ Multisite support.
1212
+ Contains ready-to-use sample vhost entries.
1313
+ Continuously updated sample configurations with best practices.
14-
+ Ansible friendly (coming soon)
14+
+ IPv6 is supported out of the box.
15+
+ Cloudflare support.
16+
+ [WebP](https://developers.google.com/speed/webp/) support.
1517

1618
## Available templates / vhost entries
1719

1820
+ WP Super Cache plugin (with support for SSL and separate mobile cache)
19-
+ WP Rocket cache plugin (SSL / mobile supported out of the box)
21+
+ WP Rocket cache plugin (SSL and / or mobile supported out of the box)
22+
+ WP Fastest Cache plugin (SSL and / or mobile supported out of the box)
2023
+ Multisite (sub-domain and sub-directory)
2124
+ Varnish with Nginx for SSL termination.
2225
+ Custom error pages.
@@ -43,10 +46,11 @@ There are multiplpe advantages of using this repo as your go-to nginx configurat
4346

4447
Tested with the following servers...
4548
+ Debian Debian 9 (Stretch)
46-
+ Ubuntu 16.04 LTS (Xenial)
49+
+ Ubuntu 16.04 LTS (Xenial Xerus)
50+
+ Ubuntu 18.04 LTS (Bionic Beaver)
4751

4852
Test with the following Nginx versions...
49-
+ Stable verisons 1.12.x
53+
+ Stable verisons 1.12.x and 1.14.x
5054
+ Mainline versions 1.13.x
5155

5256
For RPM based distros (Fedora, Redhat, CentOS and Amazon Linux AMI), the configuration mentioned in the repo should work. Additional steps may be needed, though. See below for some details!
@@ -57,7 +61,7 @@ For all the steps mentioned below, you need __sudo__ or __root__ privileges!
5761

5862
Step #1 - Install Nginx
5963

60-
You may use the official Nginx repo or just use the Nginx package that comes with the OS. Both would work fine! I will leave the decision to you. Since, the installation process varies across Operating Systems, please refer the official installation docs to complete this step.
64+
You may use the official Nginx repo or just use the Nginx package that comes with the OS. Both would work fine! I will leave the decision to you. Since, the installation process varies across Operating Systems, please refer the official installation guide to complete this step.
6165

6266
Step #2 - Please backup your existing configuration files. Probably, have /etc under version control!
6367

@@ -90,7 +94,7 @@ sudo ln -s ../sites-available/$WP_DOMAIN.conf
9094
sudo nginx -t && sudo systemctl restart nginx
9195
```
9296

93-
### Changes on CentOS
97+
### Changes on CentOS (and on rpm based distros in general)
9498

9599
CentOS has a different file naming convention, yet simple directory structure, when compared to Debian derivatives. Let me describe them and I'd let you decide upon how you'd want to structure your files and name those files.
96100

changelog.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
v3.0
2+
- Released on May 9, 2018
3+
- Rename wprocket.conf to wp-rocket.conf
4+
- Rename wpsupercache.conf to wp-super-cache.conf
5+
- Added Cloudflare support.
6+
- IPv6 support added.
7+
- WebP support.
8+
- Other minor changes.
9+
10+
v2.0
11+
- released on Dec 20, 2017
12+
- changed filename globals/common-locations.conf to globals/assets.conf
13+
- other minor changes
14+
115
v1.0
216
- released on April 23, 2017
317
- uniform naming scheme for domain names

conf.d/common.conf

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
index index.html index.php;
44

5-
# include globals/pagespeed.conf;
6-
# include globals/hide-headers.conf;
7-
# include globals/varnish-as-front-end-compatibility.conf;
8-
95
# Ref: https://gist.github.com/magnetikonline/11312172
106
fastcgi_buffers 32 32k;
117
fastcgi_buffer_size 32k;
@@ -29,8 +25,8 @@ server_names_hash_bucket_size 128;
2925

3026
# -------------------------------------------------------------------
3127

32-
# For SSL - WP Super Cache Compatibility
33-
map $scheme $wpsc_https { default ''; https '-https'; }
28+
# For SSL Compatibility - WP Super Cache and WP Rocket depend on this
29+
map $scheme $https_suffix { default ''; https '-https'; }
3430

3531
# -------------------------------------------------------------------
3632

@@ -52,3 +48,23 @@ charset $charset;
5248
charset_types *;
5349

5450
# -------------------------------------------------------------------
51+
52+
# if you'd like to hide some header info, uncomment this
53+
# include globals/hide-headers.conf;
54+
55+
# -------------------------------------------------------------------
56+
#
57+
# if you'd like to hide some header info, uncomment this
58+
# include globals/cloudflare.conf;
59+
60+
# -------------------------------------------------------------------
61+
62+
# webp support
63+
# see: https://docs.ewww.io/article/16-ewww-io-and-webp-images
64+
65+
map $http_accept $webp_suffix {
66+
default "";
67+
"~*webp" ".webp";
68+
}
69+
70+
# -------------------------------------------------------------------

globals/assets.conf

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ location ~ \.(?:ttf|ttc|eot|woff|woff2|otf|svg)$ {
2929
}
3030

3131
# Referers for images
32-
location ~ \.(?:jpg|jpeg|gif|png|ico)$ {
32+
location ~ \.(?:gif|ico|webp)$ {
3333
### Please change the domainname before uncommenting the following
3434
# valid_referers none blocked www.example.com example.com;
3535
# if ($invalid_referer) { return 403; }
@@ -39,6 +39,19 @@ location ~ \.(?:jpg|jpeg|gif|png|ico)$ {
3939
access_log off;
4040
}
4141

42+
location ~* ^.+\.(png|jpe?g)$ {
43+
### Please change the domainname before uncommenting the following
44+
# valid_referers none blocked www.example.com example.com;
45+
# if ($invalid_referer) { return 403; }
46+
47+
# add_header Vary Accept;
48+
# see https://docs.ewww.io/article/16-ewww-io-and-webp-images
49+
try_files $uri$webp_suffix $uri =404;
50+
expires max;
51+
log_not_found off;
52+
access_log off;
53+
}
54+
4255
# Feeds
4356
location ~ \.(?:rss|atom)$ {
4457
expires 600s; # 10 minutes

globals/cloudflare-ip-list.conf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
set_real_ip_from 103.21.244.0/22;
2+
set_real_ip_from 103.22.200.0/22;
3+
set_real_ip_from 103.31.4.0/22;
4+
set_real_ip_from 104.16.0.0/12;
5+
set_real_ip_from 108.162.192.0/18;
6+
set_real_ip_from 131.0.72.0/22;
7+
set_real_ip_from 141.101.64.0/18;
8+
set_real_ip_from 162.158.0.0/15;
9+
set_real_ip_from 172.64.0.0/13;
10+
set_real_ip_from 173.245.48.0/20;
11+
set_real_ip_from 188.114.96.0/20;
12+
set_real_ip_from 190.93.240.0/20;
13+
set_real_ip_from 197.234.240.0/22;
14+
set_real_ip_from 198.41.128.0/17;
15+
set_real_ip_from 2400:cb00::/32;
16+
set_real_ip_from 2405:8100::/32;
17+
set_real_ip_from 2405:b500::/32;
18+
set_real_ip_from 2606:4700::/32;
19+
set_real_ip_from 2803:f800::/32;
20+
set_real_ip_from 2c0f:f248::/32;
21+
set_real_ip_from 2a06:98c0::/29;

globals/cloudflare.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# make sure you set up a cron to run update-cloudflare-ip-list.sh regularly
2+
3+
include '/etc/nginx/globals/cloudflare-ip-list.conf';
4+
real_ip_header CF-Connecting-IP;
5+
real_ip_header CF-Connecting-IP;
6+
real_ip_recursive on;

globals/wp-fastest-cache.conf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ location / {
4141
#--> all the following would apply, only if the request hits the cache
4242

4343
# add some useful headers
44-
add_header "X-Cache" "HIT";
44+
add_header "X-Cache" "HIT - WP Fastest Cache";
4545
add_header "X-CF-Powered-By" "WP Fastest Cache";
4646
add_header "Vary" "Cookie";
4747
# include "globals/hsts.conf";
@@ -62,8 +62,7 @@ location @mobileaccess {
6262
#--> all the following would apply, only if the request hits the cache
6363

6464
# add some useful headers
65-
add_header "X-Cache" "HIT - Mobile";
66-
add_header "X-CF-Powered-By" "WP Fastest Cache";
65+
add_header "X-Cache" "HIT - Mobile - WP Fastest Cache";
6766
add_header "Vary" "User-Agent, Cookie";
6867
# include "globals/hsts.conf";
6968

globals/wprocket.conf renamed to globals/wp-rocket.conf

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,17 @@ location / {
3030
if ($http_cookie ~* "comment_author_") { return 418; }
3131
if ($http_cookie ~* "wp_postpass_") { return 418; }
3232

33-
# if ($http_user_agent ~* (2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800|iPad)) { return 419; }
33+
# if ($http_user_agent ~* "2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800|iPad") { return 419; }
3434
# add_header "Vary" "User-Agent";
3535

3636
# uncomment the following if deemed fit
37-
# if ($http_user_agent ~* (w3c\ |w3c-|acs-|alav|alca|amoi|audi|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-|dang|doco|eric|hipt|htc_|inno|ipaq|ipod|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-|lg/u|maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|palm|pana|pant|phil|play|port|prox|qwap|sage|sams|sany|sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo|teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|wap-|wapa|wapi|wapp|wapr|webc|winw|winw|xda\ |xda-|ipad)) { return 419; }
37+
# if ($http_user_agent ~* "w3c\ |w3c-|acs-|alav|alca|amoi|audi|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-|dang|doco|eric|hipt|htc_|inno|ipaq|ipod|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-|lg/u|maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|palm|pana|pant|phil|play|port|prox|qwap|sage|sams|sany|sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo|teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|wap-|wapa|wapi|wapp|wapr|webc|winw|winw|xda\ |xda-|ipad") { return 419; }
3838

39-
try_files "/wp-content/cache/wp-rocket/$host${uri}$is_args$args/index$wpsc_https.html" $uri $uri/ /index.php$is_args$args;
39+
try_files "/wp-content/cache/wp-rocket/$host${uri}$is_args$args/index$https_suffix.html" $uri $uri/ /index.php$is_args$args;
4040

4141
#--> all the following would apply, only if the request hits the cache
4242

43-
add_header "X-Cache" "HIT - Desktop";
44-
add_header "X-CF-Powered-By" "WP Rocket";
43+
add_header "X-Cache" "HIT - WP Rocket";
4544
add_header "Vary" "Cookie";
4645
# include "globals/hsts.conf";
4746

@@ -54,10 +53,9 @@ location / {
5453

5554
location @mobileaccess {
5655
# try_files $uri $uri/ /index.php$is_args$args;
57-
try_files "/wp-content/cache/wp-rocket/$host${uri}$is_args$args/index-mobile$wpsc_https.html" $uri $uri/ /index.php$is_args$args;
56+
try_files "/wp-content/cache/wp-rocket/$host${uri}$is_args$args/index-mobile$https_suffix.html" $uri $uri/ /index.php$is_args$args;
5857

59-
add_header "X-Cache" "HIT - Mobile";
60-
add_header "X-CF-Powered-By" "WP Rocket";
58+
add_header "X-Cache" "HIT - Mobile - WP Rocket";
6159
add_header "Vary" "User-Agent, Cookie";
6260
# include "globals/hsts.conf";
6361

globals/wpsc.conf renamed to globals/wp-super-cache.conf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ location / {
3030
if ($http_cookie ~* "comment_author_") { return 418; }
3131
if ($http_cookie ~* "wp_postpass_") { return 418; }
3232

33-
# if ($http_user_agent ~* (2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800|iPad)) { return 419; }
33+
# if ($http_user_agent ~* "2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800|iPad") { return 419; }
3434

3535
# uncomment the following if deemed fit
36-
# if ($http_user_agent ~* (w3c\ |w3c-|acs-|alav|alca|amoi|audi|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-|dang|doco|eric|hipt|htc_|inno|ipaq|ipod|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-|lg/u|maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|palm|pana|pant|phil|play|port|prox|qwap|sage|sams|sany|sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo|teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|wap-|wapa|wapi|wapp|wapr|webc|winw|winw|xda\ |xda-|ipad)) { return 419; }
36+
# if ($http_user_agent ~* "w3c\ |w3c-|acs-|alav|alca|amoi|audi|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-|dang|doco|eric|hipt|htc_|inno|ipaq|ipod|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-|lg/u|maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|palm|pana|pant|phil|play|port|prox|qwap|sage|sams|sany|sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo|teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|wap-|wapa|wapi|wapp|wapr|webc|winw|winw|xda\ |xda-|ipad") { return 419; }
3737

38-
try_files "/wp-content/cache/supercache/$host${uri}index$wpsc_https.html" $uri $uri/ /index.php$is_args$args;
38+
try_files "/wp-content/cache/supercache/$host${uri}index$https_suffix.html" $uri $uri/ /index.php$is_args$args;
3939

4040
#--> all the following would apply, only if the request hits the cache
4141

@@ -52,7 +52,7 @@ location / {
5252

5353
location @mobileaccess {
5454
# try_files $uri $uri/ /index.php$is_args$args;
55-
try_files "/wp-content/cache/supercache/$host${uri}index$wpsc_https-mobile.html" $uri $uri/ /index.php$is_args$args;
55+
try_files "/wp-content/cache/supercache/$host${uri}index$https_suffix-mobile.html" $uri $uri/ /index.php$is_args$args;
5656

5757
add_header "X-Cache" "HIT - Mobile - WP Super Cache";
5858
# include "globals/hsts.conf";
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
# script to set Cloudflare IPs (ipv4 and ipv6)
4+
5+
# empty the list
6+
echo -n > /etc/nginx/globals/cloudflare-ip-list.conf;
7+
8+
# fetch and update ipv4
9+
for i in `curl -s https://www.cloudflare.com/ips-v4`; do
10+
echo "set_real_ip_from $i;" >> /etc/nginx/globals/cloudflare-ip-list.conf;
11+
done
12+
13+
# fetch and update ipv6
14+
for i in `curl -s https://www.cloudflare.com/ips-v6`; do
15+
echo "set_real_ip_from $i;" >> /etc/nginx/globals/cloudflare-ip-list.conf;
16+
done

0 commit comments

Comments
 (0)