1
0
Fork 0
This commit is contained in:
root 2023-09-25 13:21:09 -04:00
parent 4edc4ccd85
commit f40a8697bc
3 changed files with 15 additions and 7 deletions

View File

@ -1,7 +1,12 @@
# Start from the official Nginx image
FROM nginx:alpine
# Copy our custom Nginx configuration
COPY nginx.conf /etc/nginx/nginx.conf
# Copy our custom Nginx configuration and script
COPY nginx.conf /etc/nginx/nginx.conf.template
COPY docker-entrypoint.sh /docker-entrypoint.sh
# Make the script executable
RUN chmod +x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]

7
docker-entrypoint.sh Normal file
View File

@ -0,0 +1,7 @@
#!/bin/sh
# Use envsubst to replace environment variables in nginx.conf.template and output to nginx.conf
envsubst '$BACKEND_ADDRESS,$BACKEND_PORT' < /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf
# Start nginx in the foreground
exec nginx -g 'daemon off;'

View File

@ -1,10 +1,6 @@
user nginx;
worker_processes 1;
# Load environment variables
env BACKEND_ADDRESS;
env BACKEND_PORT;
events {
worker_connections 1024;
}
@ -17,7 +13,7 @@ http {
listen 80;
location / {
# Use the environment variables for the proxy pass
# Use the placeholders for the proxy pass (these will be replaced by envsubst)
proxy_pass http://$BACKEND_ADDRESS:$BACKEND_PORT;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;