Skip to content

Commit 890c27f

Browse files
authored
Replace current nginx template with suspended template (hestiacp#3641)
* Replace current nginx template with suspended template Make sure traffic hitting xxx.php is not routed trough php handler and proxy pass also stops to work... * Fix bug in config-tests test * Update test * Improve test
1 parent 7093f5a commit 890c27f

File tree

7 files changed

+214
-1
lines changed

7 files changed

+214
-1
lines changed

func/domain.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ prepare_web_domain_values() {
224224
if [ "$SUSPENDED" = 'yes' ]; then
225225
docroot="$HESTIA/data/templates/web/suspend"
226226
sdocroot="$HESTIA/data/templates/web/suspend"
227+
if [ "$PROXY_SYSTEM" == "nginx" ]; then
228+
PROXY="suspended"
229+
else
230+
TPL="suspended"
231+
fi
227232
fi
228233
}
229234

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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%;
9+
server_name %domain_idn% %alias_idn%;
10+
root %docroot%;
11+
index index.html;
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+
include %home%/%user%/conf/web/%domain%/nginx.hsts.conf*;
22+
23+
location / {
24+
location ~* ^.+\.(jpeg|jpg|png|webp|gif|bmp|ico|svg|css|js)$ {
25+
expires max;
26+
fastcgi_hide_header "Set-Cookie";
27+
}
28+
29+
try_files $uri /index.html;
30+
}
31+
32+
location /error/ {
33+
alias %home%/%user%/web/%domain%/document_errors/;
34+
}
35+
36+
location ~ /\.(?!well-known\/|file) {
37+
deny all;
38+
return 404;
39+
}
40+
41+
include %home%/%user%/conf/web/%domain%/nginx.conf_*;
42+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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.html;
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+
include %home%/%user%/conf/web/%domain%/nginx.forcessl.conf*;
16+
17+
location / {
18+
location ~* ^.+\.(jpeg|jpg|png|webp|gif|bmp|ico|svg|css|js)$ {
19+
expires max;
20+
fastcgi_hide_header "Set-Cookie";
21+
}
22+
23+
try_files $uri /index.html;
24+
}
25+
26+
location /error/ {
27+
alias %home%/%user%/web/%domain%/document_errors/;
28+
}
29+
30+
location ~ /\.(?!well-known\/|file) {
31+
deny all;
32+
return 404;
33+
}
34+
35+
include %home%/%user%/conf/web/%domain%/nginx.conf_*;
36+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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%:%proxy_port%;
9+
server_name %domain_idn% %alias_idn%;
10+
root %docroot%;
11+
include %home%/%user%/conf/web/%domain%/nginx.forcessl.conf*;
12+
13+
access_log /var/log/nginx/domains/%domain%.log combined;
14+
access_log /var/log/nginx/domains/%domain%.bytes bytes;
15+
error_log /var/log/nginx/domains/%domain%.error.log error;
16+
17+
ssl_certificate %ssl_pem%;
18+
ssl_certificate_key %ssl_key%;
19+
ssl_stapling on;
20+
ssl_stapling_verify on;
21+
22+
include %home%/%user%/conf/web/%domain%/nginx.hsts.conf*;
23+
24+
location / {
25+
location ~* ^.+\.(jpeg|jpg|png|webp|gif|bmp|ico|svg|css|js)$ {
26+
expires max;
27+
fastcgi_hide_header "Set-Cookie";
28+
}
29+
30+
try_files $uri /index.html;
31+
}
32+
33+
location /error/ {
34+
alias %home%/%user%/web/%domain%/document_errors/;
35+
}
36+
37+
location ~ /\.(?!well-known\/|file) {
38+
deny all;
39+
return 404;
40+
}
41+
42+
include %home%/%user%/conf/web/%domain%/nginx.conf_*;
43+
}
44+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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%:%proxy_port%;
9+
server_name %domain_idn% %alias_idn%;
10+
root %docroot%;
11+
include %home%/%user%/conf/web/%domain%/nginx.forcessl.conf*;
12+
13+
access_log /var/log/nginx/domains/%domain%.log combined;
14+
access_log /var/log/nginx/domains/%domain%.bytes bytes;
15+
error_log /var/log/nginx/domains/%domain%.error.log error;
16+
17+
location / {
18+
location ~* ^.+\.(jpeg|jpg|png|webp|gif|bmp|ico|svg|css|js)$ {
19+
expires max;
20+
fastcgi_hide_header "Set-Cookie";
21+
}
22+
23+
try_files $uri /index.html;
24+
}
25+
26+
location /error/ {
27+
alias %home%/%user%/web/%domain%/document_errors/;
28+
}
29+
30+
location ~ /\.(?!well-known\/|file) {
31+
deny all;
32+
return 404;
33+
}
34+
35+
include %home%/%user%/conf/web/%domain%/nginx.conf_*;
36+
}

test/config-tests.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function setup() {
7373

7474
@test "Proxy Config test" {
7575
if [ "$PROXY_SYSTEM" = "nginx" ]; then
76-
for template in $(v-list-web-templates plain); do
76+
for template in $(v-list-proxy-templates plain); do
7777
run v-change-web-domain-proxy-tpl $user testhestiacp.com $template
7878
assert_success
7979
refute_output

test/test.bats

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,53 @@ function setup() {
3939
source $HESTIA/func/ip.sh
4040
}
4141

42+
function validate_web_domain() {
43+
local user=$1
44+
local domain=$2
45+
local webproof=$3
46+
local webpath=${4}
47+
48+
refute [ -z "$user" ]
49+
refute [ -z "$domain" ]
50+
refute [ -z "$webproof" ]
51+
52+
source $HESTIA/func/ip.sh
53+
54+
run v-list-web-domain $user $domain
55+
assert_success
56+
57+
USER_DATA=$HESTIA/data/users/$user
58+
local domain_ip=$(get_object_value 'web' 'DOMAIN' "$domain" '$IP')
59+
SSL=$(get_object_value 'web' 'DOMAIN' "$domain" '$SSL')
60+
domain_ip=$(get_real_ip "$domain_ip")
61+
62+
if [ ! -z $webpath ]; then
63+
domain_docroot=$(get_object_value 'web' 'DOMAIN' "$domain" '$CUSTOM_DOCROOT')
64+
if [ -n "$domain_docroot" ] && [ -d "$domain_docroot" ]; then
65+
assert_file_exist "${domain_docroot}/${webpath}"
66+
else
67+
assert_file_exist "${HOMEDIR}/${user}/web/${domain}/public_html/${webpath}"
68+
fi
69+
fi
70+
71+
# Test HTTP
72+
# Curl hates UTF domains so convert them to ascci.
73+
domain_idn=$(idn2 $domain)
74+
run curl --location --silent --show-error --insecure --resolve "${domain_idn}:80:${domain_ip}" "http://${domain_idn}/${webpath}"
75+
assert_success
76+
assert_output --partial "$webproof"
77+
78+
# Test HTTPS
79+
if [ "$SSL" = "yes" ]; then
80+
run v-list-web-domain-ssl $user $domain
81+
assert_success
82+
83+
run curl --location --silent --show-error --insecure --resolve "${domain_idn}:443:${domain_ip}" "https://${domain_idn}/${webpath}"
84+
assert_success
85+
assert_output --partial "$webproof"
86+
fi
87+
}
88+
4289
function validate_web_domain() {
4390
local user=$1
4491
local domain=$2
@@ -767,7 +814,10 @@ function check_ip_not_banned(){
767814
assert_success
768815
refute_output
769816

817+
echo -e "<?php\necho 'Hestia Test:'.(4*3);" > $HOMEDIR/$user/web/$domain/public_html/php-test.php
770818
validate_web_domain $user $domain 'This site is currently suspended'
819+
validate_web_domain $user $domain 'This site is currently suspended' 'php-test.php'
820+
rm $HOMEDIR/$user/web/$domain/public_html/php-test.php
771821
}
772822

773823
@test "WEB: Unsuspend web domain" {

0 commit comments

Comments
 (0)