我有Django项目,并尝试使用docker和nginx将其部署到服务器上。部署它并访问所需的页面没有问题,但我无法访问redoc页面。Nginx配置如下( default.conf):
server {
listen 80;
location /static/ {
root /var/html/;
}
location /media/ {
root /var/html/;
}
location /redoc/ {
root /var/html;
try_files $uri $uri/redoc.html;
}
location / {
proxy_pass http://web:8000;
}
}docker-compose.yaml:
services:
db:
image: postgres:12.4
volumes:
- postgres_data:/var/lib/postgresql/data/
env_file:
- ./.env
web:
image:
restart: always
volumes:
- static_value:/code/static/
- media_value:/code/media/
depends_on:
- db
env_file:
- ./.env
nginx:
image: nginx:1.19.3
ports:
- "80:80"
volumes:
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
- static_value:/var/html/static/
- media_value:/var/html/media/
- .static/redoc.yaml:/var/html/redoc/redoc.yaml
- .templates/redoc.html:/var/html/redoc/redoc.html
depends_on:
- web
volumes:
postgres_data:
static_value:
media_value:你能建议一下,哪里出了问题吗?
发布于 2021-11-21 16:24:39
尝试修复volumes中redoc.html的路径。如果此html文件位于文件夹templates内,则位于docker-compose.yml旁边,而不是
- .templates/redoc.html:/var/html/redoc/redoc.html试一试
- ./templates/redoc.html:/var/html/redoc/redoc.html然后转到http://<ip-address>/redoc/进行访问(末尾有斜杠)。
https://stackoverflow.com/questions/70054139
复制相似问题