Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuration of ports 80 and 443 #142

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions image/pro_seafile/templates/seafile.nginx.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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 }};
Expand All @@ -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;
Expand Down
14 changes: 9 additions & 5 deletions image/seafile/templates/seafile.nginx.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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 }};
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions scripts/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
14 changes: 9 additions & 5 deletions templates/seafile.nginx.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 }};
Expand All @@ -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;
Expand Down