-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.wordpress.nginx.virtualhost.conf
165 lines (148 loc) · 5.88 KB
/
example.wordpress.nginx.virtualhost.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
upstream examplecombackend {
server unix:/var/run/php-fcgi-examplecom.sock;
}
server {
listen 80 default;
server_name example.com;
return 301 https://example.com$request_uri;
}
server {
listen 80;
server_name www.example.com;
return 301 https://example.com$request_uri;
}
server {
listen 443 ssl;
server_name www.example.com;
return 301 https://example.com$request_uri;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
}
server {
listen 443 ssl default;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
root /home/example.com/public_html;
index index.php;
access_log /home/examplecom/logs/access.log;
error_log /home/examplecom/logs/error.log;
location / {
include /home/examplecom/public_html/nginx.conf;
add_header X-Cache-Status $upstream_cache_status;
try_files $uri $uri/ /index.php?$args;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires 24h;
log_not_found off;
}
location ^~ /.well-known {
try_files $uri $uri/ @handler;
index index.php index.html;
}
location /. {
return 404;
}
location @handler {
rewrite ^/(.*)$ /index.php;
}
location ~ ^/wp-(admin|login).php {
location ~ \.php$ {
# Setup caching
set $no_cache "";
# Don't cache POSTs
if ($request_method = POST) {
set $no_cache 1;
}
# Don’t cache uris containing the following segments
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
set $no_cache 1;
}
# Don’t use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
set $no_cache 1;
}
fastcgi_no_cache $no_cache;
fastcgi_cache_bypass $no_cache;
fastcgi_cache drm_custom_cache;
fastcgi_cache_key $server_name|$request_uri;
# Cache times
fastcgi_cache_valid 404 60m;
fastcgi_cache_valid 200 60m;
fastcgi_max_temp_file_size 4m;
fastcgi_cache_use_stale updating;
fastcgi_pass_header Set-Cookie;
fastcgi_pass_header Cookie;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
fastcgi_intercept_errors on;
fastcgi_pass welcometotravelbackend;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
location ~ \.php$ {
# Setup caching
set $no_cache "";
# Don't cache POSTs
if ($request_method = POST) {
set $no_cache 1;
}
# Don’t cache uris containing the following segments
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
set $no_cache 1;
}
# Don’t use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
$no_cache 1;
}
fastcgi_no_cache $no_cache;
fastcgi_cache_bypass $no_cache;
fastcgi_cache drm_custom_cache;
fastcgi_cache_key $server_name|$request_uri;
# Cache times
fastcgi_cache_valid 404 60m;
fastcgi_cache_valid 200 60m;
fastcgi_max_temp_file_size 4m;
fastcgi_cache_use_stale updating;
fastcgi_pass_header Set-Cookie;
fastcgi_pass_header Cookie;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
fastcgi_index index.php;
fastcgi_intercept_errors on;
fastcgi_pass examplecombackend;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# Caching
location ~* \.(ico|jpg|webp|jpeg|gif|css|png|js|ico|bmp|zip|woff)$ {
access_log off;
log_not_found off;
add_header Pragma public;
add_header Cache-Control "public";
expires 14d;
}
location ~* \.(php|html)$ {
access_log on;
log_not_found on;
add_header Pragma public;
add_header Cache-Control "public";
expires 14d;
}
# SECURITY
# Ignore other host headers
if ($host !~* ^(example.com|www.example.com)$ ) {
return 444;
}
# Obfuscation rule (hide identifying files)
location ~ /(\.|wp-config.php|readme.html|licence.txt) {
return 404;
}
# Only allow GET , POST, and HEAD
if ($request_method !~ ^(GET|POST|HEAD)$ ) {
return 444;
}
# Disable viewing of hidden files (files starting with a dot)
location ~ /\. {
deny all;
}
}