Skip to content

Commit bd09101

Browse files
jaapmarcushudokkow
andauthored
Fix: hestiacp#3729 Missing robots.txt get redirected to WP (hestiacp#3739) / Add WordPress Multisite subdir support (hestiacp#3741)
* Fix: hestiacp#3729 Missing robots.txt get redirected to WP * [nginx/templates] Add WordPress Multisite subdir support (hestiacp#3741) Co-authored-by: h.udo <hudokkow@gmail.com>
1 parent 2cc58d5 commit bd09101

File tree

8 files changed

+380
-4
lines changed

8 files changed

+380
-4
lines changed

install/deb/templates/web/nginx/php-fpm/wordpress.stpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ server {
3030
}
3131

3232
location = /robots.txt {
33-
allow all;
33+
try_files $uri $uri/ /index.php?$args;
3434
log_not_found off;
3535
access_log off;
3636
}

install/deb/templates/web/nginx/php-fpm/wordpress.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ server {
2121
}
2222

2323
location = /robots.txt {
24-
allow all;
24+
try_files $uri $uri/ /index.php?$args;
2525
log_not_found off;
2626
access_log off;
2727
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#=========================================================================#
2+
# Default Web Domain Template #
3+
# DO NOT MODIFY THIS FILE! CHANGES WILL BE LOST WHEN REBUILDING DOMAINS #
4+
# https://hestiacp.com/docs/server-administration/web-templates.html #
5+
#=========================================================================#
6+
7+
server {
8+
listen %ip%:%web_ssl_port% ssl;
9+
server_name %domain_idn% %alias_idn%;
10+
root %sdocroot%;
11+
index index.php index.html index.htm;
12+
access_log /var/log/nginx/domains/%domain%.log combined;
13+
access_log /var/log/nginx/domains/%domain%.bytes bytes;
14+
error_log /var/log/nginx/domains/%domain%.error.log error;
15+
16+
ssl_certificate %ssl_pem%;
17+
ssl_certificate_key %ssl_key%;
18+
ssl_stapling on;
19+
ssl_stapling_verify on;
20+
21+
# TLS 1.3 0-RTT anti-replay
22+
if ($anti_replay = 307) { return 307 https://$host$request_uri; }
23+
if ($anti_replay = 425) { return 425; }
24+
25+
include %home%/%user%/conf/web/%domain%/nginx.hsts.conf*;
26+
27+
# Rewrite requests to /wp-.* on subdirectory installs.
28+
if (!-e $request_filename) {
29+
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
30+
rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
31+
rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
32+
}
33+
34+
location = /favicon.ico {
35+
log_not_found off;
36+
access_log off;
37+
}
38+
39+
location = /robots.txt {
40+
try_files $uri $uri/ /index.php?$args;
41+
log_not_found off;
42+
access_log off;
43+
}
44+
45+
location ~ /\.(?!well-known\/) {
46+
deny all;
47+
return 404;
48+
}
49+
50+
location / {
51+
try_files $uri $uri/ /index.php?$args;
52+
53+
location ~* ^.+\.(ogg|ogv|svg|svgz|swf|eot|otf|woff|woff2|mov|mp3|mp4|webm|flv|ttf|rss|atom|jpg|jpeg|gif|png|webp|ico|bmp|mid|midi|wav|rtf|css|js|jar)$ {
54+
expires 30d;
55+
fastcgi_hide_header "Set-Cookie";
56+
}
57+
58+
location ~* /(?:uploads|files)/.*.php$ {
59+
deny all;
60+
return 404;
61+
}
62+
63+
location ~ [^/]\.php(/|$) {
64+
try_files $uri =404;
65+
66+
include /etc/nginx/fastcgi_params;
67+
68+
fastcgi_index index.php;
69+
fastcgi_param HTTP_EARLY_DATA $rfc_early_data if_not_empty;
70+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
71+
72+
fastcgi_pass %backend_lsnr%;
73+
74+
include %home%/%user%/conf/web/%domain%/nginx.fastcgi_cache.conf*;
75+
76+
if ($request_uri ~* "/wp-admin/|/wp-json/|wp-.*.php|xmlrpc.php|index.php|/store.*|/cart.*|/my-account.*|/checkout.*") {
77+
set $no_cache 1;
78+
}
79+
80+
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in|woocommerce_items_in_cart|woocommerce_cart_hash|PHPSESSID") {
81+
set $no_cache 1;
82+
}
83+
}
84+
}
85+
86+
location /error/ {
87+
alias %home%/%user%/web/%domain%/document_errors/;
88+
}
89+
90+
location /vstats/ {
91+
alias %home%/%user%/web/%domain%/stats/;
92+
include %home%/%user%/web/%domain%/stats/auth.conf*;
93+
}
94+
95+
proxy_hide_header Upgrade;
96+
97+
include /etc/nginx/conf.d/phpmyadmin.inc*;
98+
include /etc/nginx/conf.d/phppgadmin.inc*;
99+
include %home%/%user%/conf/web/%domain%/nginx.ssl.conf_*;
100+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#=========================================================================#
2+
# Default Web Domain Template #
3+
# DO NOT MODIFY THIS FILE! CHANGES WILL BE LOST WHEN REBUILDING DOMAINS #
4+
# https://hestiacp.com/docs/server-administration/web-templates.html #
5+
#=========================================================================#
6+
7+
server {
8+
listen %ip%:%web_port%;
9+
server_name %domain_idn% %alias_idn%;
10+
root %docroot%;
11+
index index.php index.html index.htm;
12+
access_log /var/log/nginx/domains/%domain%.log combined;
13+
access_log /var/log/nginx/domains/%domain%.bytes bytes;
14+
error_log /var/log/nginx/domains/%domain%.error.log error;
15+
16+
include %home%/%user%/conf/web/%domain%/nginx.forcessl.conf*;
17+
18+
# Rewrite requests to /wp-.* on subdirectory installs.
19+
if (!-e $request_filename) {
20+
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
21+
rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
22+
rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
23+
}
24+
25+
location = /favicon.ico {
26+
log_not_found off;
27+
access_log off;
28+
}
29+
30+
location = /robots.txt {
31+
try_files $uri $uri/ /index.php?$args;
32+
log_not_found off;
33+
access_log off;
34+
}
35+
36+
location ~ /\.(?!well-known\/) {
37+
deny all;
38+
return 404;
39+
}
40+
41+
location / {
42+
try_files $uri $uri/ /index.php?$args;
43+
44+
location ~* ^.+\.(ogg|ogv|svg|svgz|swf|eot|otf|woff|woff2|mov|mp3|mp4|webm|flv|ttf|rss|atom|jpg|jpeg|gif|png|webp|ico|bmp|mid|midi|wav|rtf|css|js|jar)$ {
45+
expires 30d;
46+
fastcgi_hide_header "Set-Cookie";
47+
}
48+
49+
location ~* /(?:uploads|files)/.*.php$ {
50+
deny all;
51+
return 404;
52+
}
53+
54+
location ~ [^/]\.php(/|$) {
55+
try_files $uri =404;
56+
57+
include /etc/nginx/fastcgi_params;
58+
59+
fastcgi_index index.php;
60+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
61+
62+
fastcgi_pass %backend_lsnr%;
63+
64+
include %home%/%user%/conf/web/%domain%/nginx.fastcgi_cache.conf*;
65+
66+
if ($request_uri ~* "/wp-admin/|/wp-json/|wp-.*.php|xmlrpc.php|index.php|/store.*|/cart.*|/my-account.*|/checkout.*") {
67+
set $no_cache 1;
68+
}
69+
70+
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in|woocommerce_items_in_cart|woocommerce_cart_hash|PHPSESSID") {
71+
set $no_cache 1;
72+
}
73+
}
74+
}
75+
76+
location /error/ {
77+
alias %home%/%user%/web/%domain%/document_errors/;
78+
}
79+
80+
location /vstats/ {
81+
alias %home%/%user%/web/%domain%/stats/;
82+
include %home%/%user%/web/%domain%/stats/auth.conf*;
83+
}
84+
85+
include /etc/nginx/conf.d/phpmyadmin.inc*;
86+
include /etc/nginx/conf.d/phppgadmin.inc*;
87+
include %home%/%user%/conf/web/%domain%/nginx.conf_*;
88+
}

install/rpm/templates/web/nginx/php-fpm/wordpress.stpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ server {
3030
}
3131

3232
location = /robots.txt {
33-
allow all;
33+
try_files $uri $uri/ /index.php?$args;
3434
log_not_found off;
3535
access_log off;
3636
}

install/rpm/templates/web/nginx/php-fpm/wordpress.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ server {
2121
}
2222

2323
location = /robots.txt {
24-
allow all;
24+
try_files $uri $uri/ /index.php?$args;
2525
log_not_found off;
2626
access_log off;
2727
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#=========================================================================#
2+
# Default Web Domain Template #
3+
# DO NOT MODIFY THIS FILE! CHANGES WILL BE LOST WHEN REBUILDING DOMAINS #
4+
# https://hestiacp.com/docs/server-administration/web-templates.html #
5+
#=========================================================================#
6+
7+
server {
8+
listen %ip%:%web_ssl_port% ssl;
9+
server_name %domain_idn% %alias_idn%;
10+
root %sdocroot%;
11+
index index.php index.html index.htm;
12+
access_log /var/log/nginx/domains/%domain%.log combined;
13+
access_log /var/log/nginx/domains/%domain%.bytes bytes;
14+
error_log /var/log/nginx/domains/%domain%.error.log error;
15+
16+
ssl_certificate %ssl_pem%;
17+
ssl_certificate_key %ssl_key%;
18+
ssl_stapling on;
19+
ssl_stapling_verify on;
20+
21+
# TLS 1.3 0-RTT anti-replay
22+
if ($anti_replay = 307) { return 307 https://$host$request_uri; }
23+
if ($anti_replay = 425) { return 425; }
24+
25+
include %home%/%user%/conf/web/%domain%/nginx.hsts.conf*;
26+
27+
# Rewrite requests to /wp-.* on subdirectory installs.
28+
if (!-e $request_filename) {
29+
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
30+
rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
31+
rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
32+
}
33+
34+
location = /favicon.ico {
35+
log_not_found off;
36+
access_log off;
37+
}
38+
39+
location = /robots.txt {
40+
try_files $uri $uri/ /index.php?$args;
41+
log_not_found off;
42+
access_log off;
43+
}
44+
45+
location ~ /\.(?!well-known\/) {
46+
deny all;
47+
return 404;
48+
}
49+
50+
location / {
51+
try_files $uri $uri/ /index.php?$args;
52+
53+
location ~* ^.+\.(ogg|ogv|svg|svgz|swf|eot|otf|woff|woff2|mov|mp3|mp4|webm|flv|ttf|rss|atom|jpg|jpeg|gif|png|webp|ico|bmp|mid|midi|wav|rtf|css|js|jar)$ {
54+
expires 30d;
55+
fastcgi_hide_header "Set-Cookie";
56+
}
57+
58+
location ~* /(?:uploads|files)/.*.php$ {
59+
deny all;
60+
return 404;
61+
}
62+
63+
location ~ [^/]\.php(/|$) {
64+
try_files $uri =404;
65+
66+
include /etc/nginx/fastcgi_params;
67+
68+
fastcgi_index index.php;
69+
fastcgi_param HTTP_EARLY_DATA $rfc_early_data if_not_empty;
70+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
71+
72+
fastcgi_pass %backend_lsnr%;
73+
74+
include %home%/%user%/conf/web/%domain%/nginx.fastcgi_cache.conf*;
75+
76+
if ($request_uri ~* "/wp-admin/|/wp-json/|wp-.*.php|xmlrpc.php|index.php|/store.*|/cart.*|/my-account.*|/checkout.*") {
77+
set $no_cache 1;
78+
}
79+
80+
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in|woocommerce_items_in_cart|woocommerce_cart_hash|PHPSESSID") {
81+
set $no_cache 1;
82+
}
83+
}
84+
}
85+
86+
location /error/ {
87+
alias %home%/%user%/web/%domain%/document_errors/;
88+
}
89+
90+
location /vstats/ {
91+
alias %home%/%user%/web/%domain%/stats/;
92+
include %home%/%user%/web/%domain%/stats/auth.conf*;
93+
}
94+
95+
proxy_hide_header Upgrade;
96+
97+
include /etc/nginx/conf.d/phpmyadmin.inc*;
98+
include /etc/nginx/conf.d/phppgadmin.inc*;
99+
include %home%/%user%/conf/web/%domain%/nginx.ssl.conf_*;
100+
}

0 commit comments

Comments
 (0)