[#1659] Refactor server configuration to support multiple HTTP and HTTPS ports with common options for improved flexibility

This commit is contained in:
Théophile Diot 2025-01-07 19:46:51 +01:00
parent b59afa049b
commit 675913ae8b
No known key found for this signature in database
GPG key ID: FA995104A0BA376A
4 changed files with 59 additions and 26 deletions

View file

@ -8,11 +8,17 @@ server {
server_name _;
# HTTP listen
{% if LISTEN_HTTP == "yes" +%}
listen 0.0.0.0:{{ HTTP_PORT }} default_server {% if USE_PROXY_PROTOCOL == "yes" %}proxy_protocol{% endif %};
{% endif %}
{% if USE_IPV6 == "yes" +%}
listen [::]:{{ HTTP_PORT }} default_server {% if USE_PROXY_PROTOCOL == "yes" %}proxy_protocol{% endif %};
{% if LISTEN_HTTP == "yes" %}
{% set common_options = " default_server" %}
{% if USE_PROXY_PROTOCOL == "yes" %}
{% set common_options = common_options ~ " proxy_protocol" %}
{% endif %}
{% for k, port in all.items() if k.startswith("HTTP_PORT") %}
listen 0.0.0.0:{{ port }}{{ common_options }};
{% if USE_IPV6 == "yes" %}
listen [::]:{{ port }}{{ common_options }};
{% endif %}
{% endfor %}
{% endif %}
# HTTPS listen
@ -36,17 +42,25 @@ server {
{% if HTTP2 == "yes" %}
http2 on;
{% endif %}
listen 0.0.0.0:{{ HTTPS_PORT }} ssl default_server {% if USE_PROXY_PROTOCOL == "yes" %}proxy_protocol{% endif %};
{% if USE_IPV6 == "yes" +%}
listen [::]:{{ HTTPS_PORT }} ssl default_server {% if USE_PROXY_PROTOCOL == "yes" %}proxy_protocol{% endif %};
{% set common_options = " ssl default_server" %}
{% if USE_PROXY_PROTOCOL == "yes" %}
{% set common_options = common_options ~ " proxy_protocol" %}
{% endif %}
{% for k, port in all.items() if k.startswith("HTTPS_PORT") %}
listen 0.0.0.0:{{ port }}{{ common_options }};
{% if USE_IPV6 == "yes" %}
listen [::]:{{ port }}{{ common_options }};
{% endif %}
{% endfor %}
{% if "TLSv1.3" in SSL_PROTOCOLS and HTTP3 == "yes" and USE_PROXY_PROTOCOL == "no" %}
http3 on;
listen 0.0.0.0:{{ HTTPS_PORT }} quic default_server reuseport;
{% if USE_IPV6 == "yes" +%}
listen [::]:{{ HTTPS_PORT }} quic default_server reuseport;
{% endif %}
{% for k, port in all.items() if k.startswith("HTTPS_PORT") %}
listen 0.0.0.0:{{ port }} quic default_server;
{% if USE_IPV6 == "yes" %}
listen [::]:{{ port }} quic default_server;
{% endif %}
{% endfor %}
add_header Alt-Svc 'h3=":{{ HTTP3_ALT_SVC_PORT }}"; ma=86400';
{% endif %}
{% endif %}

View file

@ -3,11 +3,20 @@ server {
server_name {{ SERVER_NAME }};
# HTTP listen
{% if LISTEN_HTTP == "yes" +%}
listen 0.0.0.0:{{ HTTP_PORT }}{% if MULTISITE == "no" and DISABLE_DEFAULT_SERVER == "no" %} default_server{% endif %}{% if USE_PROXY_PROTOCOL == "yes" %} proxy_protocol{% endif %};
{% endif %}
{% if USE_IPV6 == "yes" +%}
listen [::]:{{ HTTP_PORT }}{% if MULTISITE == "no" and DISABLE_DEFAULT_SERVER == "no" %} default_server{% endif %}{% if USE_PROXY_PROTOCOL == "yes" %} proxy_protocol{% endif %};
{% if LISTEN_HTTP == "yes" %}
{% set common_options = "" %}
{% if MULTISITE == "no" and DISABLE_DEFAULT_SERVER == "no" %}
{% set common_options = common_options ~ " default_server" %}
{% endif %}
{% if USE_PROXY_PROTOCOL == "yes" %}
{% set common_options = common_options ~ " proxy_protocol" %}
{% endif %}
{% for k, port in all.items() if k.startswith("HTTP_PORT") %}
listen 0.0.0.0:{{ port }}{{ common_options }};
{% if USE_IPV6 == "yes" %}
listen [::]:{{ port }}{{ common_options }};
{% endif %}
{% endfor %}
{% endif %}
index index.php index.html index.htm;

View file

@ -17,17 +17,25 @@ ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDS
{% if HTTP2 == "yes" %}
http2 on;
{% endif %}
listen 0.0.0.0:{{ HTTPS_PORT }} ssl {% if USE_PROXY_PROTOCOL == "yes" %}proxy_protocol{% endif %};
{% if USE_IPV6 == "yes" +%}
listen [::]:{{ HTTPS_PORT }} ssl {% if USE_PROXY_PROTOCOL == "yes" %}proxy_protocol{% endif %};
{% set common_options = " ssl" %}
{% if USE_PROXY_PROTOCOL == "yes" %}
{% set common_options = common_options ~ " proxy_protocol" %}
{% endif %}
{% for k, port in all.items() if k.startswith("HTTPS_PORT") %}
listen 0.0.0.0:{{ port }}{{ common_options }};
{% if USE_IPV6 == "yes" %}
listen [::]:{{ port }}{{ common_options }};
{% endif %}
{% endfor %}
{% if "TLSv1.3" in SSL_PROTOCOLS and HTTP3 == "yes" and USE_PROXY_PROTOCOL == "no" %}
http3 on;
listen 0.0.0.0:{{ HTTPS_PORT }} quic;
{% if USE_IPV6 == "yes" +%}
listen [::]:{{ HTTPS_PORT }} quic;
{% endif %}
{% for k, port in all.items() if k.startswith("HTTPS_PORT") %}
listen 0.0.0.0:{{ port }} quic;
{% if USE_IPV6 == "yes" %}
listen [::]:{{ port }} quic;
{% endif %}
{% endfor %}
add_header Alt-Svc 'h3=":{{ HTTP3_ALT_SVC_PORT }}"; ma=86400';
{% endif %}

View file

@ -24,7 +24,8 @@
"id": "http-port",
"label": "HTTP port",
"regex": "^\\d+$",
"type": "text"
"type": "text",
"multiple": "listen-http-ports"
},
"HTTPS_PORT": {
"context": "global",
@ -33,7 +34,8 @@
"id": "https-port",
"label": "HTTPS port",
"regex": "^\\d+$",
"type": "text"
"type": "text",
"multiple": "listen-https-ports"
},
"MULTISITE": {
"context": "global",