Nginx重定向到Docker中Django应用的Sphinx文档

问题描述

我已将Sphinx文档添加到Django项目中,并希望提供从/docs uri生成的Sphinx页面,但是我似乎无法使uri和目录保持一致以提供正确的内容。我已经尝试了多种配置。下面是当前列表。

Django站点运行正常(尽管还没有设置静态文件内容-那里我也有同样的问题!)。但是/docsNginx返回404。

我尝试过rootalias和其他路径设置。我已验证该卷已在/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 (将#修改为@)