【发布时间】:2019-07-25 14:37:22
【问题描述】:
我有一个应用程序,它的前端在 React 中,后端在 Django 中,前端使用 DRF 开发的 API。现在我将 Nginx 与 Gunicorn 一起用作 Web 服务器。以下是我在 sites-available 中的 Nginx conf 文件:
server {
listen 8000;
server_name localhost;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/nokia-ui/build/;
}
location /nokia-sdn/api/v1/ {
proxy_pass http://127.0.0.1:8000/nokia-sdn/api/v1/;
}
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://unix:/home/nokia-sdn/nokia.sock;
}
}
现在当我访问http://localhost:8000/时,我得到了登录页面,但我无法向后端发出任何api请求。我们是否需要在nginx文件中定义API的路径,如果是什么是格式吗?
【问题讨论】:
-
API 请求会发生什么?对于这些请求,浏览器的网络选项卡在开发者工具中显示什么?
-
显示方法不允许错误
-
您的 API 请求是否使用路径
/nokia-sdn/api/v1/?
标签: django nginx django-rest-framework gunicorn