Django nginx docker
First I apologize if this is a duplicate, but I have not found a solution through similar posts shown in SO
I have a Docker Django image that uses nginx and gunicorn.
Gunicorn script:
exec /var/www/venv/bin/gunicorn wsgi:application \
--bind 0.0.0.0:8001 \
--access-logfile /var/log/gunicorn/access.log \
--error-logfile /var/log/gunicorn/error.log
Nginx config:
server {
server_name 172.0.0.1;
access_log off;
location / {
proxy_pass http://127.0.0.1:8001;
proxy_set_header Host $host:$server_port;
}
location /static/ {
autoindex on;
alias /var/www/django/assets/;
expires 7d;
}
}
I expose port 80 and map it to 49260.
When looking at the external docker IP port, including the port where the site is published and serving static files.
http://xxx.xx.xx.xxx:49260/
The problem is, when I go to any other page on the django site, the mapped port is removed from the url, which is then picked by the host server ngnix config.
What I am trying to achieve is to maintain a port in the url, which can later be overridden by the proxy from the host server.
Any advice would be really appreciated.
source to share
The response added:
proxy_set_header Host $http_host;
for nginx conf which prints hostname: portnumber
See serverfault.com link here: Original theme
source to share