diff --git a/swarm-proxy/01-copy-default-entry.sh b/swarm-proxy/01-copy-default-entry.sh index d73adff4b9c84b66c4c40f72ae4b43290d248c51..20f7d5146e016474f58a6c2b6bb884097127d727 100755 --- a/swarm-proxy/01-copy-default-entry.sh +++ b/swarm-proxy/01-copy-default-entry.sh @@ -73,23 +73,21 @@ proxy_set_header Proxy ""; ## Catch all Servers ############################################################################ +upstream gitlab_pages_upstream { + server host.docker.internal:8080; +} + server { listen 80 default_server; server_name _; - location ^~ /.well-known/acme-challenge/ { - auth_basic off; - auth_request off; - allow all; - root /usr/share/nginx/html; - try_files \$uri =404; - break; - } + include /etc/nginx/vhost.d/git.qoto.org*; + include /etc/nginx/vhost.d/default*; location / { - root /usr/share/nginx/html; - index index.html index.htm; + proxy_pass http://gitlab_pages_upstream; } } + EOF diff --git a/swarm-proxy/99-swarm-proxy-entry.sh b/swarm-proxy/99-swarm-proxy-entry.sh index 10cfc787662f1a4499c8814b5a2e9544af983e48..d73adff4b9c84b66c4c40f72ae4b43290d248c51 100755 --- a/swarm-proxy/99-swarm-proxy-entry.sh +++ b/swarm-proxy/99-swarm-proxy-entry.sh @@ -1,35 +1,95 @@ #!/bin/bash set -e -# Warn if the DOCKER_HOST socket does not exist -if [[ $DOCKER_HOST = unix://* ]]; then - socket_file=${DOCKER_HOST#unix://} - if ! [ -S $socket_file ]; then - cat >&2 <<-EOT -ERROR: you need to share your Docker host socket with a volume at $socket_file -Typically you should run your qotoorg/swarm-proxy with: \`-v /var/run/docker.sock:$socket_file:ro\` -See the documentation at http://git.io/vZaGJ -EOT - socketMissing=1 - fi -fi - -# Generate dhparam file if required -# Note: if $DHPARAM_BITS is not defined, generate-dhparam.sh will use 4096 as a default -# Note2: if $DHPARAM_GENERATION is set to false in environment variable, dh param generator will skip completely -generate-dhparam $DHPARAM_BITS $DHPARAM_GENERATION - -# Compute the DNS resolvers for use in the templates - if the IP contains ":", it's IPv6 and must be enclosed in [] -export RESOLVERS=$(awk '$1 == "nameserver" {print ($2 ~ ":")? "["$2"]": $2}' ORS=' ' /etc/resolv.conf | sed 's/ *$//g') -if [ "x$RESOLVERS" = "x" ]; then - echo "Warning: unable to determine DNS resolvers for nginx" >&2 - unset RESOLVERS -else - echo "Resolvers successfully set to: ${RESOLVERS}" -fi - -# If the user has run the default command and the socket doesn't exist, fail -if [ "$socketMissing" = 1 -a "$1" = "/docker-run.sh" ]; then - echo "Exiting due to missing docker socket" - exit -1 -fi +echo "Copying default.conf to conf.d directory" +cat > "/etc/nginx/conf.d/default.conf" << EOF +############################################################################ +## General Configuration +############################################################################ + +# If we receive X-Forwarded-Proto, pass it through; otherwise, pass along the +# scheme used to connect to this server +map \$http_x_forwarded_proto \$proxy_x_forwarded_proto { + default \$http_x_forwarded_proto; + '' \$scheme; +} + +# If we receive X-Forwarded-Port, pass it through; otherwise, pass along the +# server port the client connected to +map \$http_x_forwarded_port \$proxy_x_forwarded_port { + default \$http_x_forwarded_port; + '' \$server_port; +} + +# If we receive Upgrade, set Connection to "upgrade"; otherwise, delete any +# Connection header that may have been passed to this server +map \$http_upgrade \$proxy_connection { + default upgrade; + '' close; +} + +# Apply fix for very long server names +server_names_hash_bucket_size 128; + +# Default dhparam +ssl_dhparam /etc/nginx/dhparam/dhparam.pem; + +# Set appropriate X-Forwarded-Ssl header +map \$scheme \$proxy_x_forwarded_ssl { + default off; + https on; +} + +gzip_types text/plain text/css application/javascript application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; + +log_format vhost '\$host \$remote_addr - \$remote_user [\$time_local] ' + '"\$request" \$status \$body_bytes_sent ' + '"\$http_referer" "\$http_user_agent"'; + +access_log off; + ssl_protocols TLSv1.2 TLSv1.3; + ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384'; + ssl_prefer_server_ciphers off; + +resolver 10.0.0.2; + +# HTTP 1.1 support +proxy_http_version 1.1; +proxy_buffering off; +proxy_set_header Host \$http_host; +proxy_set_header Upgrade \$http_upgrade; +proxy_set_header Connection \$proxy_connection; +proxy_set_header X-Real-IP \$remote_addr; +proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; +proxy_set_header X-Forwarded-Proto \$proxy_x_forwarded_proto; +proxy_set_header X-Forwarded-Ssl \$proxy_x_forwarded_ssl; +proxy_set_header X-Forwarded-Port \$proxy_x_forwarded_port; + +# Mitigate httpoxy attack (see README for details) +proxy_set_header Proxy ""; + + +############################################################################ +## Catch all Servers +############################################################################ + +server { + listen 80 default_server; + server_name _; + + location ^~ /.well-known/acme-challenge/ { + auth_basic off; + auth_request off; + allow all; + root /usr/share/nginx/html; + try_files \$uri =404; + break; + } + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + } +} + +EOF diff --git a/swarm-proxy/docker-compose.yml b/swarm-proxy/docker-compose.yml index 781f43c871c9900999305d9e6d77c1c842811626..a48ef08b7dba86771a8adafb087d3b65b1f2d9c1 100644 --- a/swarm-proxy/docker-compose.yml +++ b/swarm-proxy/docker-compose.yml @@ -1,10 +1,5 @@ version: '2' services: swarm-proxy: - image: qotoorg/swarm-proxy:latest - container_name: swarm-proxy - ports: - - "80:80" - - "443:443" - volumes: - - /var/run/docker.sock:/var/run/docker.sock:ro + image: modjular/swarm-proxy:latest + build: . diff --git a/swarm-proxy/swarm-proxy.tmpl b/swarm-proxy/swarm-proxy.tmpl index 69cb3c2f62ed048f2abe2c6516a8a4c6af2c4944..0d057ec4c36d2860be5a33cf1b0b869813d9e9aa 100644 --- a/swarm-proxy/swarm-proxy.tmpl +++ b/swarm-proxy/swarm-proxy.tmpl @@ -4,20 +4,11 @@ upstream ${HOST}_upstream { } server { - server_name ${HOST}; - listen 80 ; + server_name ${HOST}; + listen 80; - location ^~ /.well-known/acme-challenge/ { - auth_basic off; - allow all; - root /usr/share/nginx/html; - try_files $uri =404; - break; - } - - - include /opt/nginx/vhost.d/${HOST}*; - include /opt/nginx/vhost.d/default*; + include /etc/nginx/vhost.d/${HOST}*; + include /etc/nginx/vhost.d/default*; location / { proxy_pass http://${HOST}_upstream;