فهرست منبع

HESTIA-NGINX: Automatic listing on IPV4 or/and IPV6 address (#3593)

Co-authored-by: asmcc <root@test.hestiacp.com>
Jaap Marcus 2 سال پیش
والد
کامیت
243eb86fd2
2فایلهای تغییر یافته به همراه19 افزوده شده و 1 حذف شده
  1. 17 0
      src/deb/nginx/hestia
  2. 2 1
      src/deb/nginx/nginx.conf

+ 17 - 0
src/deb/nginx/hestia

@@ -17,6 +17,7 @@ NGINX_DAEMON=/usr/local/hestia/nginx/sbin/hestia-nginx
 NGINX_NAME=hestia-nginx
 NGINX_NAME=hestia-nginx
 NGINX_DESC=hestia-nginx
 NGINX_DESC=hestia-nginx
 NGINX_PID=/run/hestia-nginx.pid
 NGINX_PID=/run/hestia-nginx.pid
+NGINX_CONF=/usr/local/hestia/nginx/conf/nginx.conf
 
 
 PHP_DAEMON=/usr/local/hestia/php/sbin/hestia-php
 PHP_DAEMON=/usr/local/hestia/php/sbin/hestia-php
 PHP_NAME=hestia-php
 PHP_NAME=hestia-php
@@ -30,7 +31,23 @@ set -e
 
 
 . /etc/profile.d/hestia.sh
 . /etc/profile.d/hestia.sh
 
 
+adapt_nginx_config() {
+	ipv4_string="$(ip -4 addr show scope global | sed -ne '/^[ \t]*inet[6]*/p')"
+	ipv6_string="$(ip -6 addr show scope global | sed -ne '/^[ \t]*inet[6]*/p')"
+	if [ -n "$ipv4_string" ]; then
+		sed -i 's/#IPV4\([ \t]*listen[ \t]*[0-9]\{1,5\}.*\)/\1/' ${NGINX_CONF}
+	else
+		sed -i 's/^\([ \t]*listen[ \t]*[0-9]\{1,5\}.*\)/#IPV4\1/' ${NGINX_CONF}
+	fi
+	if [ -n "$ipv6_string" ]; then
+		sed -i 's/#IPV6\([ \t]*listen[ \t]*\[\:\:\]\:[0-9]\{1,5\}.*\)/\1/' ${NGINX_CONF}
+	else
+		sed -i 's/^\([ \t]*listen[ \t]*\[\:\:\]\:[0-9]\{1,5\}.*\)/#IPV6\1/' ${NGINX_CONF}
+	fi
+}
+
 start_nginx() {
 start_nginx() {
+	adapt_nginx_config
 	start-stop-daemon --start --quiet --pidfile $NGINX_PID \
 	start-stop-daemon --start --quiet --pidfile $NGINX_PID \
 		--retry 5 --exec $NGINX_DAEMON --oknodo
 		--retry 5 --exec $NGINX_DAEMON --oknodo
 }
 }

+ 2 - 1
src/deb/nginx/nginx.conf

@@ -92,7 +92,8 @@ http {
 
 
 	# Vhost
 	# Vhost
 	server {
 	server {
-		listen              8083 ssl;
+		#IPV4		listen				8083 ssl;
+		#IPV6		listen				[::]:8083 ssl;
 		server_name         _;
 		server_name         _;
 		root                /usr/local/hestia/web;
 		root                /usr/local/hestia/web;
 		# Fix error "The plain HTTP request was sent to HTTPS port"
 		# Fix error "The plain HTTP request was sent to HTTPS port"