DjangoでNginxのUnix Socketを利用する
upstream blog_app_server { # fail_timeout=0 means we always retry an upstream even if it failed # to return a good HTTP response (in case the Unicorn master nukes a # single worker for timing out). server unix:/opt/example.com/run/gunicorn.sock fail_timeout=0; } server { listen 80; server_name www.example.com example.com; server_tokens off; access_log /opt/example.com/logs/nginx-access.log; error_log /opt/example.com/logs/nginx-error.log; location /static/ { alias /opt/example.com/static/; } location / { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; if (!-f $request_filename) { proxy_pass http://blog_app_server; break; } } # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }
Docker間はVolumeでマウントする
What's should Django ALLOWED_HOSTS be when using a unix socket?
Nginx: プロキシ・リバースプロキシ・WEBサーバー Gunicorn: APサーバー uWsgi: GateWay, Interface