diff --git a/.env.example b/.env.example index b3dfd0e..20ca403 100644 --- a/.env.example +++ b/.env.example @@ -15,3 +15,7 @@ POSTGRES_DB=routerfleet POSTGRES_USER=routerfleet POSTGRES_PASSWORD=your_database_password +# If you need to serve the app using HTTP and HTTPS, change the following variable to 'never' +# Using HTTP is not recommended, as it is less secure and your passwords will be sent in plain text. +# Use with caution. +# HTTPS_REDIRECT_POLICY=always diff --git a/.gitignore b/.gitignore index 6d901f4..523f351 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ routerfleet/production_settings.py .idea/ db.sqlite3 backups/ -containers/*/.venv \ No newline at end of file +containers/*/.venv +.env \ No newline at end of file diff --git a/containers/nginx/Dockerfile-nginx b/containers/nginx/Dockerfile-nginx index 884b315..c5430be 100644 --- a/containers/nginx/Dockerfile-nginx +++ b/containers/nginx/Dockerfile-nginx @@ -1,7 +1,8 @@ FROM nginx:alpine RUN apk --no-cache add openssl COPY nginx_entrypoint.sh /nginx_entrypoint.sh -COPY virtualhost.conf /etc/nginx/conf.d/default.conf +COPY virtualhost.conf /etc/nginx/virtualhost.conf.disabled +COPY virtualhost_noredirect.conf /etc/nginx/virtualhost_noredirect.conf.disabled RUN chmod +x /nginx_entrypoint.sh ENTRYPOINT ["/nginx_entrypoint.sh"] CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/containers/nginx/nginx_entrypoint.sh b/containers/nginx/nginx_entrypoint.sh index b42a32e..9dde9ba 100644 --- a/containers/nginx/nginx_entrypoint.sh +++ b/containers/nginx/nginx_entrypoint.sh @@ -9,4 +9,13 @@ else echo "Skipping self signed certificate creation, files already exist." fi +if [ "$HTTPS_REDIRECT_POLICY" = "never" ]; then + echo "Copying /etc/nginx/virtualhost_noredirect.conf to /etc/nginx/conf.d/default.conf..." + cp /etc/nginx/virtualhost_noredirect.conf.disabled /etc/nginx/conf.d/default.conf +else + echo "Copying /etc/nginx/virtualhost.conf to /etc/nginx/conf.d/default.conf..." + cp /etc/nginx/virtualhost.conf.disabled /etc/nginx/conf.d/default.conf +fi + + exec "$@" \ No newline at end of file diff --git a/containers/nginx/virtualhost_noredirect.conf b/containers/nginx/virtualhost_noredirect.conf new file mode 100644 index 0000000..0b2dc15 --- /dev/null +++ b/containers/nginx/virtualhost_noredirect.conf @@ -0,0 +1,35 @@ +server { + listen 80; + + location /static/ { + alias /static/; + } + + location / { + proxy_pass http://routerfleet:8001; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } +} + +server { + listen 443 ssl; + ssl_certificate /certificate/nginx.pem; + ssl_certificate_key /certificate/nginx.key; + + # if you are using cloudflare, you can use this enable authenticated origin pull. Dont forget to activate it in cloudflare + #ssl_client_certificate /certificate/cloudflare_authenticated_origin_pull_ca.pem; + #ssl_verify_client on; + + location /static/ { + alias /static/; + } + + location / { + proxy_pass http://routerfleet:8001; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } +} diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index 31c818e..4c69eda 100644 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -60,6 +60,8 @@ services: build: context: ./containers/nginx dockerfile: Dockerfile-nginx + environment: + - HTTPS_REDIRECT_POLICY=${HTTPS_REDIRECT_POLICY} volumes: - static_volume:/static - https_cert:/certificate diff --git a/docker-compose-no-postgres.yml b/docker-compose-no-postgres.yml index 9e8a74f..303ed07 100644 --- a/docker-compose-no-postgres.yml +++ b/docker-compose-no-postgres.yml @@ -38,6 +38,8 @@ services: container_name: routerfleet-nginx restart: unless-stopped image: eduardosilva/routerfleet-nginx:latest + environment: + - HTTPS_REDIRECT_POLICY=${HTTPS_REDIRECT_POLICY} volumes: - static_volume:/static - https_cert:/certificate diff --git a/docker-compose.yml b/docker-compose.yml index 1a0c85e..27f3dd1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -51,6 +51,8 @@ services: container_name: routerfleet-nginx restart: unless-stopped image: eduardosilva/routerfleet-nginx:latest + environment: + - HTTPS_REDIRECT_POLICY=${HTTPS_REDIRECT_POLICY} volumes: - static_volume:/static - https_cert:/certificate diff --git a/entrypoint.sh b/entrypoint.sh index 4d9fced..bc430f3 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -64,7 +64,7 @@ fi cat > $PRODUCTION_SETTINGS_FILE <