Reputation: 21
I create proxy container with docker and generate ssl certificates to my domain with jwilder/nginx-proxy. It's works, but now tried redirect my django apps by subdomain and every request return 502 bad gateway. I'm a noob to this. I need help to know what I'm doing wrong.
This is my docker-compose nginx-proxy:
version: '3'
services:
nginx-proxy:
image: jwilder/nginx-proxy
restart: always
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- certs:/etc/nginx/certs:ro
- vhostd:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
labels:
- com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy
letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion
restart: always
environment:
- NGINX_PROXY_CONTAINER=nginx-proxy
volumes:
- certs:/etc/nginx/certs:rw
- vhostd:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- /var/run/docker.sock:/var/run/docker.sock:ro
www:
image: nginx
restart: always
expose:
- "80"
volumes:
- /Users/kbs/git/peladonerd/varios/1/www:/usr/share/nginx/html:ro
environment:
- VIRTUAL_HOST=pablokbs.com,www.pablokbs.com
- LETSENCRYPT_HOST=pablokbs.com,www.pablokbs.com
- [email protected]
depends_on:
- nginx-proxy
- letsencrypt
volumes:
certs:
html:
vhostd:
and this is docker-compose django app (bak_web is app to redirect by subdomain):
version: "3"
services:
core_api:
build:
context: .
env_file: .env
container_name: "bak-api"
ports:
- 8181:8181
volumes:
- ./BAK_API:/bak_api
- ./bak:/bak_api
command: uvicorn bak.asgi:app --host 0.0.0.0 --port 8181
bak_web:
build:
context: .
expose:
- "80"
env_file: .env
container_name: "bak-web"
volumes:
- static:/bak_web/static
- .:/bak_web
- ./bak_chatbot:/app
nginx-bak-web:
image: nginx
restart: always
expose:
- "80"
volumes:
- ./config/nginx/conf.d:/etc/nginx/conf.d
- static:/bak_web/static
environment:
- VIRTUAL_HOST=bakzion.duckdns.org
- LETSENCRYPT_HOST=bakzion.duckdns.org
- [email protected]
depends_on:
- bak_web
volumes:
.:
static:
last this is local.conf configuration:
upstream bakzion.duckdns.org {
server bak_web:80;
}
server {
listen 80;
server_name bakzion.duckdns.org;
location /static/{
alias /bak_web/static/;
}
location / {
include uwsgi_params;
uwsgi_pass uwsgi://webapp.docker.localhost;
include /etc/nginx/vhost.d/default_location;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
uwsgi_read_timeout 180;
}
}
I tried create proxy docker with nginx to redirect every django app host in server
Upvotes: 0
Views: 545
Reputation: 11
do you really need this part?:
www:
image: nginx
restart: always
expose:
- "80"
volumes:
- /Users/kbs/git/peladonerd/varios/1/www:/usr/share/nginx/html:ro
environment:
- VIRTUAL_HOST=pablokbs.com,www.pablokbs.com
- LETSENCRYPT_HOST=pablokbs.com,www.pablokbs.com
- [email protected]
depends_on:
- nginx-proxy
- letsencrypt
It's pointed to a domain of another Person, maybe that is making a conflic. I've recently hosted two sites with jwilder an both of them work.
Example of my jwilder config:
nginx-proxy:
image: bbtsoftwareag/nginx-proxy-unrestricted-requestsize:alpine
networks:
- nginx-net
container_name: nginx-proxy
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- certs:/etc/nginx/certs:ro
- vhostd:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
# If you have default config, user next line: (from a config folder of your project)
- ./config/default_location:/etc/nginx/vhost.d/default_location
- myProject_static_myProject:/myProject/static
- myProject_media_myProject:/myProject/media
- myProject2_static_myProject2:/myProject2/static
- myProject2_media_myProject2:/myProject2/media
labels:
- com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy
letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion
restart: always
environment:
- NGINX_PROXY_CONTAINER=nginx-proxy
volumes:
- certs:/etc/nginx/certs:rw
- vhostd:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- /var/run/docker.sock:/var/run/docker.sock:ro
volumes:
certs:
html:
vhostd:
myProject_static_myProject:
external: true
myProject_media_myProject:
external: true
myProject2_static_myProject2:
external: true
myProject2_media_myProject2:
external: true
#If you have a network
networks:
nginx-net:
name: network_name
As the Pelado Nerd says... IMPRESIONANTE!
Upvotes: 1