diff --git a/image/pro_seafile/templates/seafile.nginx.conf.template b/image/pro_seafile/templates/seafile.nginx.conf.template index 3e4e59c8..66239956 100644 --- a/image/pro_seafile/templates/seafile.nginx.conf.template +++ b/image/pro_seafile/templates/seafile.nginx.conf.template @@ -2,7 +2,7 @@ # Auto generated at {{ current_timestr }} {% if https -%} server { - listen 80; + listen {{ http_port }}; server_name _ default_server; # allow certbot to connect to challenge location via HTTP Port 80 # otherwise renewal request will fail @@ -12,14 +12,14 @@ server { } location / { - rewrite ^ https://{{ domain }}$request_uri? permanent; + rewrite ^ https://{{ domain }}:(( https_port }}$request_uri? permanent; } } {% endif -%} server { {% if https -%} - listen 443; + listen {{ https_port }}; ssl on; ssl_certificate /shared/ssl/{{ domain }}.crt; ssl_certificate_key /shared/ssl/{{ domain }}.key; @@ -32,7 +32,7 @@ server { # ssl_session_cache shared:SSL:10m; # ssl_session_timeout 10m; {% else -%} - listen 80; + listen {{ http_port }}; {% endif -%} server_name {{ domain }}; @@ -42,7 +42,11 @@ server { location / { proxy_pass http://127.0.0.1:8000/; proxy_read_timeout 310s; - proxy_set_header Host $host; +{% if https -%} + proxy_set_header Host $host:{{ https_port }}; +{% else -%} + proxy_set_header Host $host:{{ http_port }}; +{% endif -%} proxy_set_header Forwarded "for=$remote_addr;proto=$scheme"; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; diff --git a/image/seafile/templates/seafile.nginx.conf.template b/image/seafile/templates/seafile.nginx.conf.template index 321131ba..834e1d77 100644 --- a/image/seafile/templates/seafile.nginx.conf.template +++ b/image/seafile/templates/seafile.nginx.conf.template @@ -2,7 +2,7 @@ # Auto generated at {{ current_timestr }} {% if https -%} server { - listen 80; + listen {{ http_port }}; server_name _ default_server; # allow certbot to connect to challenge location via HTTP Port 80 @@ -13,14 +13,14 @@ server { } location / { - rewrite ^ https://{{ domain }}$request_uri? permanent; + rewrite ^ https://{{ domain }}:{{ https_port }}$request_uri? permanent; } } {% endif -%} server { {% if https -%} - listen 443; + listen {{ https_port }}; ssl on; ssl_certificate /shared/ssl/{{ domain }}.crt; ssl_certificate_key /shared/ssl/{{ domain }}.key; @@ -33,7 +33,7 @@ server { # ssl_session_cache shared:SSL:10m; # ssl_session_timeout 10m; {% else -%} - listen 80; + listen {{ http_port }}; {% endif -%} server_name {{ domain }}; @@ -43,7 +43,11 @@ server { location / { proxy_pass http://127.0.0.1:8000/; proxy_read_timeout 310s; - proxy_set_header Host $host; +{% if https -%} + proxy_set_header Host $host:{{ https_port }}; +{% else -%} + proxy_set_header Host $host:{{ http_port }}; +{% endif -%} proxy_set_header Forwarded "for=$remote_addr;proto=$scheme"; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; diff --git a/scripts/bootstrap.py b/scripts/bootstrap.py index 6b21a85a..25a87635 100755 --- a/scripts/bootstrap.py +++ b/scripts/bootstrap.py @@ -74,9 +74,13 @@ def init_letsencrypt(): def generate_local_nginx_conf(): # Now create the final nginx configuratin domain = get_conf('SEAFILE_SERVER_HOSTNAME', 'seafile.example.com') + http_port = get_conf('SEAFILE_SERVER_HTTP_PORT', '80') + https_port = get_conf('SEAFILE_SERVER_HTTPS_PORT', '443') context = { 'https': is_https(), 'domain': domain, + 'http_port': http_port, + 'https_port': https_port, } render_template( '/templates/seafile.nginx.conf.template', diff --git a/templates/seafile.nginx.conf.template b/templates/seafile.nginx.conf.template index fe02cb00..331a41d1 100644 --- a/templates/seafile.nginx.conf.template +++ b/templates/seafile.nginx.conf.template @@ -2,15 +2,15 @@ # Auto generated at {{ current_timestr }} {% if https -%} server { - listen 80; + listen {{ http_port }}; server_name _ default_server; - rewrite ^ https://{{ domain }}$request_uri? permanent; + rewrite ^ https://{{ domain }}:{{ https_port }}$request_uri? permanent; } {% endif -%} server { {% if https -%} - listen 443; + listen {{ https_port }}; ssl on; ssl_certificate /shared/ssl/{{ domain }}.crt; ssl_certificate_key /shared/ssl/{{ domain }}.key; @@ -23,7 +23,7 @@ server { # ssl_session_cache shared:SSL:10m; # ssl_session_timeout 10m; {% else -%} - listen 80; + listen {{ http_port }}; {% endif -%} server_name {{ domain }}; @@ -33,7 +33,11 @@ server { location / { proxy_pass http://127.0.0.1:8000/; proxy_read_timeout 310s; - proxy_set_header Host $host; +{% if https -%} + proxy_set_header Host $host:{{ https_port }}; +{% else -%} + proxy_set_header Host $host:{{ http_port }}; +{% endif -%} proxy_set_header Forwarded "for=$remote_addr;proto=$scheme"; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-Proto $scheme;