我正在建立一个Django REST framework的API,通过Gunicorn和Nginx提供服务.项目“exampleproject”必须在子路径上运行,例如:https://100.100.100.100/exampleproject(示例IP地址).我没有为IP注册的域名.
目前,起始页面在https://100.100.100.100/exampleproject处按预期呈现.但是“产品”的资源路径不起作用.而不是https://100.100.100.100/exampleproject/products,起始页面显示https://100.100.100.100/products – 这不起作用.
我在/ etc / Nginx / sites-enabled / default中配置了exampleproject的子路径,如下所示:
server {
# ...
location /exampleproject/ {
proxy_pass http://localhost:8007/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
当我手动访问https://100.100.100.100/exampleproject/products时,Nginx会在/var/log/Nginx/access.log中记录以下内容:
“GET /products/ HTTP/1.1” 404 151 “-“
最佳答案
原文链接:https://www.f2er.com/nginx/434580.html