I am struggling with the connection of nginx and django (docker container)
My strategy is like this ,
run uwsgi http
option and 8001
port. (not socket)
uwsgi --http :8001 --module myapp.wsgi --py-autoreload 1 --logto /tmp/mylog.log
then I confirmed wget http://127.0.0.1:8001
works.
but from, nginx
, It can't connect somehow. (111: Connection refused)
error
However from nginx wget http://django:8001
works.
How can I connect between containars
upstream django {
ip_hash;
server 127.0.0.1:8001;
}
server {
listen 8000;
server_name 127.0.0.1;
charset utf-8;
location /static {
alias /static;
}
location / {
proxy_pass http://127.0.0.1:8001/;
include /etc/nginx/uwsgi_params;
}
}
server_tokens off;
I am trying this config but, if I try this, my container doesn't launch.
log is like this
2020/03/24 08:24:04 [emerg] 1#1: upstream "django" may not have port 8001 in /etc/nginx/conf.d/app_nginx.conf:16
upstream django {
ip_hash;
server django:8001;
}
server {
listen 8000;
server_name 127.0.0.1;
charset utf-8;
location /static {
alias /static;
}
location / {
proxy_pass http://django:8001/;
include /etc/nginx/uwsgi_params;
}
}
server_tokens off;
my docker compose is very simple...
nginx:
image: nginx:1.13
container_name: nginx
ports:
- "8000:8000"
volumes:
- ./nginx/conf:/etc/nginx/conf.d
- ./nginx/uwsgi_params:/etc/nginx/uwsgi_params
- ./nginx/static:/static
depends_on:
- django
Finally thanks to helps. my server works. final conf is like this below.
remove upstream
and use name 'django' instead of 127.0.0.1
server {
listen 8000;
server_name 127.0.0.1;
charset utf-8;
location /static {
alias /static;
}
location / {
proxy_pass http://django:8001/;
include /etc/nginx/uwsgi_params;
}
}
server_tokens off;