Skip to content

Commit 4c813dd

Browse files
author
Kristan Kenney
committed
Redirect unassigned hosts to default page
The server will return a generic "Success!" page when navigating via IP or an unassigned domain name.
1 parent d319fcf commit 4c813dd

File tree

5 files changed

+124
-0
lines changed

5 files changed

+124
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Listen directIP:8080
2+
Listen directIP:8443
3+
4+
<VirtualHost directIP:80>
5+
6+
DocumentRoot /var/www/html/
7+
Alias /error/ /var/www/document_errors/
8+
9+
</VirtualHost>
10+
11+
<VirtualHost directIP:443>
12+
13+
DocumentRoot /var/www/html/
14+
Alias /error/ /var/www/document_errors/
15+
16+
</VirtualHost>

install/deb/nginx/unassigned.inc

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
server {
2+
listen directIP:80 default;
3+
server_name _;
4+
location / {
5+
access_log /dev/null;
6+
error_log /dev/null;
7+
root /var/www/html;
8+
9+
location /phpmyadmin/ {
10+
alias /var/www/document_errors/;
11+
return 404;
12+
}
13+
14+
location /phppgadmin/ {
15+
alias /var/www/document_errors/;
16+
return 404;
17+
}
18+
19+
location /webmail {
20+
alias /var/www/document_errors/;
21+
return 404;
22+
}
23+
24+
location /webmail/ {
25+
alias /var/www/document_errors/;
26+
return 404;
27+
}
28+
29+
location /error/ {
30+
alias /var/www/document_errors/;
31+
}
32+
}
33+
}
34+
35+
server {
36+
listen directIP:443 ssl http2 default;
37+
server_name _;
38+
ssl_certificate /usr/local/hestia/ssl/certificate.crt;
39+
ssl_certificate_key /usr/local/hestia/ssl/certificate.key;
40+
41+
return 301 http://$host$request_uri;
42+
43+
location / {
44+
root /var/www/document_errors/;
45+
}
46+
47+
location /error/ {
48+
alias /var/www/document_errors/;
49+
}
50+
}

install/hst-install-debian.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,17 @@ if [ "$nginx" = 'yes' ]; then
10721072
service php$fpm_v-fpm start >> $LOG
10731073
check_result $? "php$fpm_v-fpm start failed"
10741074
fi
1075+
1076+
# Redirect unassigned hosts to default "Success" page
1077+
if [ -f /usr/local/hestia/data/ips/* ]; then
1078+
for ip in /usr/local/hestia/data/ips/*; do
1079+
ipaddr=${ip##*/}
1080+
rm -f /etc/nginx/conf.d/$ip.conf
1081+
cp -f $HESTIA/install/deb/nginx/unassigned.inc /etc/nginx/conf.d/$ipaddr.conf
1082+
sed -i 's/directIP/'$ipaddr'/g' /etc/nginx/conf.d/$ipaddr.conf
1083+
done
1084+
fi
1085+
10751086
update-rc.d nginx defaults > /dev/null 2>&1
10761087
service nginx start >> $LOG
10771088
check_result $? "nginx start failed"
@@ -1118,6 +1129,17 @@ if [ "$apache" = 'yes' ]; then
11181129
sed -i 's/#//g' $HESTIA/data/templates/web/apache2/*.stpl
11191130
fi
11201131
fi
1132+
1133+
# Add unassigned hosts configuration to apache2
1134+
if [ -f /usr/local/hestia/data/ips/* ]; then
1135+
for ip in /usr/local/hestia/data/ips/*; do
1136+
ipaddr=${ip##*/}
1137+
rm -f /etc/apache2/conf.d/$ip.conf
1138+
cp -f $HESTIA/install/deb/apache2/unassigned.conf /etc/apache2/conf.d/$ipaddr.conf
1139+
sed -i 's/directIP/'$ipaddr'/g' /etc/apache2/conf.d/$ipaddr.conf
1140+
done
1141+
fi
1142+
11211143
update-rc.d apache2 defaults > /dev/null 2>&1
11221144
service apache2 start >> $LOG
11231145
check_result $? "apache2 start failed"

install/hst-install-ubuntu.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,17 @@ if [ "$nginx" = 'yes' ]; then
10501050
service php$fpm_v-fpm start >> $LOG
10511051
check_result $? "php$fpm_v-fpm start failed"
10521052
fi
1053+
1054+
# Redirect unassigned hosts to default "Success" page
1055+
if [ -f /usr/local/hestia/data/ips/* ]; then
1056+
for ip in /usr/local/hestia/data/ips/*; do
1057+
ipaddr=${ip##*/}
1058+
rm -f /etc/nginx/conf.d/$ip.conf
1059+
cp -f $HESTIA/install/deb/nginx/unassigned.inc /etc/nginx/conf.d/$ipaddr.conf
1060+
sed -i 's/directIP/'$ipaddr'/g' /etc/nginx/conf.d/$ipaddr.conf
1061+
done
1062+
fi
1063+
10531064
update-rc.d nginx defaults > /dev/null 2>&1
10541065
service nginx start >> $LOG
10551066
check_result $? "nginx start failed"
@@ -1092,6 +1103,17 @@ if [ "$apache" = 'yes' ]; then
10921103
done
10931104
chmod a+x $HESTIA/data/templates/web/apache2/*.sh
10941105
fi
1106+
1107+
# Add unassigned hosts configuration to apache2
1108+
if [ -f /usr/local/hestia/data/ips/* ]; then
1109+
for ip in /usr/local/hestia/data/ips/*; do
1110+
ipaddr=${ip##*/}
1111+
rm -f /etc/apache2/conf.d/$ip.conf
1112+
cp -f $HESTIA/install/deb/apache2/unassigned.conf /etc/apache2/conf.d/$ipaddr.conf
1113+
sed -i 's/directIP/'$ipaddr'/g' /etc/apache2/conf.d/$ipaddr.conf
1114+
done
1115+
fi
1116+
10951117
update-rc.d apache2 defaults > /dev/null 2>&1
10961118
service apache2 start >> $LOG
10971119
check_result $? "apache2 start failed"

install/upgrade/0.9.8-28.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,20 @@ chmod 751 $HESTIA/data/templates/web/unassigned/css
125125
chmod 751 $HESTIA/data/templates/web/unassigned/js
126126
chmod 751 $HESTIA/data/templates/web/unassigned/webfonts
127127

128+
# Add unassigned hosts configuration to nginx and apache2
129+
if [ -f /usr/local/hestia/data/ips/* ]; then
130+
for ip in /usr/local/hestia/data/ips/*; do
131+
ipaddr=${ip##*/}
132+
rm -f /etc/nginx/conf.d/$ip.conf
133+
cp -f $HESTIA/install/deb/nginx/unassigned.inc /etc/nginx/conf.d/$ipaddr.conf
134+
sed -i 's/directIP/'$ipaddr'/g' /etc/nginx/conf.d/$ipaddr.conf
135+
136+
rm -f /etc/apache2/conf.d/$ip.conf
137+
cp -f $HESTIA/install/deb/apache2/unassigned.conf /etc/apache2/conf.d/$ipaddr.conf
138+
sed -i 's/directIP/'$ipaddr'/g' /etc/apache2/conf.d/$ipaddr.conf
139+
done
140+
fi
141+
128142
# Set Purge to false in roundcube config - https://goo.gl/3Nja3u
129143
if [ -f /etc/roundcube/config.inc.php ]; then
130144
sed -i "s/\['flag_for_deletion'] = 'Purge';/\['flag_for_deletion'] = false;/gI" /etc/roundcube/config.inc.php

0 commit comments

Comments
 (0)