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

support for reverse proxy in front of web-proxy over http #26

Open
wants to merge 1 commit into
base: main
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
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ ADD nginx/snikket-common.template /etc/nginx/templates/snikket-common
ADD nginx/startup.template /etc/nginx/templates/startup
ADD nginx/http.template /etc/nginx/templates/http
ADD nginx/https.template /etc/nginx/templates/https
ADD nginx/proxy.template /etc/nginx/templates/proxy
ADD service /etc/sv
ADD static /var/www/html/static
ADD startup.html /var/www/html/index.html
Expand Down
8 changes: 6 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#!/bin/bash
#!/bin/sh

export SNIKKET_DOMAIN_ASCII=$(idn2 "$SNIKKET_DOMAIN")

CERT_PATH="/snikket/letsencrypt/live/$SNIKKET_DOMAIN_ASCII/fullchain.pem"

PROTOS="${SNIKKET_TWEAK_WEB_PROXY_PROTOS:-http https}"

if test -f "$CERT_PATH"; then
if [ "$SNIKKET_REVERSE_PROXIED" = "1" ]; then
## assume certs already exist - render and deploy configs
/usr/local/bin/render-template.sh "/etc/nginx/templates/snikket-common" "/etc/nginx/snippets/snikket-common.conf"
/usr/local/bin/render-template.sh "/etc/nginx/templates/proxy" "/etc/nginx/sites-enabled/proxy";
elif test -f "$CERT_PATH"; then
## Certs already exist - render and deploy configs
/usr/local/bin/render-template.sh "/etc/nginx/templates/snikket-common" "/etc/nginx/snippets/snikket-common.conf"
for proto in $PROTOS; do
Expand Down
69 changes: 69 additions & 0 deletions nginx/proxy.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
server {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How this file was derived:

  1. copy https template
  2. Remove all SSL bits
  3. Use http port

listen ${SNIKKET_TWEAK_HTTP_PORT};
listen [::]:${SNIKKET_TWEAK_HTTP_PORT};

add_header Strict-Transport-Security "max-age=63072000" always;

server_name ${SNIKKET_DOMAIN_ASCII};

include "/etc/nginx/snippets/snikket-common.conf";
}

server {
listen ${SNIKKET_TWEAK_HTTP_PORT};
listen [::]:${SNIKKET_TWEAK_HTTP_PORT};

add_header Strict-Transport-Security "max-age=63072000" always;

server_name share.${SNIKKET_DOMAIN_ASCII};

root /var/www/html;

location / {
return 301 https://${SNIKKET_DOMAIN_ASCII}/;
}

location /upload/ {
client_max_body_size 104857616; # 100MB + 16 bytes (see Prosody config)
proxy_request_buffering off;
proxy_http_version 1.1;
proxy_pass http://${SNIKKET_TWEAK_INTERNAL_HTTP_HOST}:${SNIKKET_TWEAK_INTERNAL_HTTP_PORT};
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
}
}

server {
listen ${SNIKKET_TWEAK_HTTP_PORT};
listen [::]:${SNIKKET_TWEAK_HTTP_PORT};

add_header Strict-Transport-Security "max-age=63072000" always;

server_name groups.${SNIKKET_DOMAIN_ASCII};

root /var/www/html;

location / {
return 301 https://${SNIKKET_DOMAIN_ASCII}/;
}
}

# Fail requests to unknown domains
server {
listen ${SNIKKET_TWEAK_HTTP_PORT} default_server;
listen [::]:${SNIKKET_TWEAK_HTTP_PORT} default_server;

add_header Strict-Transport-Security "max-age=63072000" always;

error_page 404 /_errors/404_site.html;

location = /_errors/404_site.html {
root /var/www/html;
internal;
}

location / {
try_files none =404;
}
}