如何解决Nginx重定向到Docker中Django应用的Sphinx文档
我已将Sphinx文档添加到Django项目中,并希望提供从/docs
uri生成的Sphinx页面,但是我似乎无法使uri和目录保持一致以提供正确的内容。我已经尝试了多种配置。下面是当前列表。
Django站点运行正常(尽管还没有设置静态文件的内容-那里我也有同样的问题!)。但是/docs
从nginx返回404。
我尝试过root
与alias
和其他路径设置。我已验证该卷已在/docs
上正常加载,因此index.html
在那里存在,但没有任何乐趣。
欢迎所有建议!
docker-compose.yml
version: '3.8'
services:
nginx:
image: nginx
ports:
- 443:443
- 80:80
volumes:
- ./config/nginx:/etc/nginx/conf.d
- ./static:/static
- ./src/docs/build/html:/docs
depends_on:
- web
web:
container_name: inventory
build:
context: .
dockerfile: Dockerfile.dev
env_file: .env
volumes:
- ./src:/inventory
- ./config/nginx/certs:/etc/certs
expose:
- 443
environment:
- DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE}
command: >
<Does stuff & runs gunicorn>
nginx.conf
upstream web {
ip_hash;
server web:443;
}
# Redirect all HTTP requests to HTTPS
server {
listen 80;
server_name localhost;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name localhost;
# Serve up the Sphinx docs directly
location /docs {
# root /docs;
try_files $uri $uri.html $uri/ index.html;
}
# Pass request to the web container
location / {
proxy_pass https://web/;
}
# SSL properties
# (http://nginx.org/en/docs/http/configuring_https_servers.html)
ssl_certificate /etc/nginx/conf.d/certs/localhost.crt;
ssl_certificate_key /etc/nginx/conf.d/certs/localhost.key;
root /usr/share/nginx/html;
add_header Strict-Transport-Security "max-age=31536000" always;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。