我有两个用于Django应用程序的容器:一个用于应用程序本身,另一个用于nginx服务器。
它的工作正常,但是有一个功能需要一点时间,在完成之前,我会收到 504网关超时错误。
docker-compose.yml 文件包含以下服务:
services:
dj:
build:
context: .
dockerfile: prd/dj/Dockerfile
volumes:
- ./sharepoint:/sharepoint
- static_files:/sharepoint/static/
- media_files:/sharepoint/media/
ports:
- 8000:8000
command: gunicorn -w 4 sharepoint.wsgi --bind 0.0.0.0:8000
nx:
build:
context: .
dockerfile: prd/nx/Dockerfile
volumes:
- static_files:/static_files
- media_files:/media_files
ports:
- 8090:80
- 8091:443
nginx的 Dockerfile 包含以下内容:
FROM nginx:latest
RUN rm /etc/nginx/conf.d/default.conf
COPY ./prd/nx/nx.conf /etc/nginx/conf.d
nx.conf 包含以下内容:
server {
listen 80;
listen 443;
server_name localhost;
access_log /var/log/nginx/example.log;
location /static/ {
autoindex off;
alias /static_files/;
}
location /media/ {
autoindex off;
alias /media_files/;
}
location / {
proxy_pass http://dj:8000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
我在Nginx 504 Gateway Timeout Error for Django
中找到了解决方案将超时ngnix设置设置为以下位置的http {...}块 /etc/nginx/nginx.conf文件:
http { #All block content... #Now the timeout settings: proxy_connect_timeout 50000; proxy_read_timeout 50000; proxy_send_timeout 50000; }
重启nginx
我尝试过但没有成功。我没有http {}
块。
我试图将超时设置设置为location / {}
,但无法正常工作。