我有一个可行的解决方案,其中我已配置Traefik,NGINX,Gunicorn和Django的docker环境-都可以正常工作。静态内容由NGINX提供。我的问题是我将www DNS名称添加到x.com-NGINX无法提供静态内容。
这是我的default.conf文件:
server {
listen 80;
server_name _;
# server_name _;
client_max_body_size 200M;
set $cache_uri $request_uri;
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; }
ignore_invalid_headers on;
add_header Access-Control-Allow_Origin *;
location /static {
autoindex on;
alias /static;
}
location /media {
autoindex on;
alias /media;
}
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
}
我尝试将server_name更改为x.com www.x.com,但结果是相同的。
以下是我的docker-compose.yml文件的NGINX部分
nginx:
image: nginx:alpine
container_name: ${CONTAINER_NGINX}
restart: always
volumes:
- ./default.conf:/etc/nginx/conf.d/default.conf
- ./saleor/static/:/static
networks:
- proxy
- ${DOCKER_NETWORK_INTERNAL_NAME}
labels:
- "traefik.enable=true"
- "traefik.backend=${CONTAINER_NGINX}"
- "traefik.frontend.rule=Host:x.com;PathPrefix:/static,www.x.com;PathPrefix:/static"
- "traefik.docker.network=proxy"
- "traefik.port=80"