【发布时间】:2020-09-03 02:53:11
【问题描述】:
我有一个加载在 https://xxx.xxx.xxx.xxx/ 上的 Angular 应用程序,在代理服务器 (Nginx) 后面提供服务。
在同一台服务器上,我托管了我的后端 (django),当我尝试使用 domain-ip/api/users 访问任何“API”服务时,我得到了
Page not found (404)
Request Method: GET
Request URL: http://xxx.xx.xx.xxx/api/users/
当我检查 nginx 日志时,没有记录最近的日志来突出显示任何错误。
-
这是我的 /etc/nginx/sites-available/default
服务器{ 听 80 default_server; 听 [::]:80 default_server;
#root points to my angular app root /home/bc_sparrow/bc_s/frontend/dist; # Add index.php to the list if you are using PHP index index.html index.htm index.nginx-debian.html; server_name 138.xx.55.xxx; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ /index.html; } location /api/ { include proxy_params; proxy_pass http://unix:/run/gunicorn.sock; #proxy_set_header Host $http_host; #adding this line made things worse proxy_set_header X-Forwarded-Host $server_name; proxy_set_header X-Real-IP $remote_addr; }}
使用上面的配置,当我运行这两个命令时,我没有收到错误。
sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled
sudo nginx -t
当我运行 sudo systemctl status gunicorn 时,我得到了
gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; disabled; vendor preset: enabled)
Active: active (running) since Sun 2020-05-17 03:31:33 UTC; 29min ago
Main PID: 14011 (gunicorn)
Tasks: 4 (limit: 1151)
CGroup: /system.slice/gunicorn.service
├─14011 /home/bc_sparrow/bc_s/backend/merchant/env/bin/python /home/bc_sparrow/bc_s/backend/merchant/env ├─14033 /home/bc_sparrow/bc_s/backend/merchant/env/bin/python /home/bc_sparrow/bc_s/backend/merchant/env ├─14038 /home/bc_sparrow/bc_s/backend/merchant/env/bin/python /home/bc_sparrow/bc_s/backend/merchant/env └─14039 /home/bc_sparrow/bc_s/backend/merchant/env/bin/python /home/bc_sparrow/bc_s/backend/merchant/env
May 17 03:31:33 SparrowsV1 systemd[1]: Stopped gunicorn daemon.
May 17 03:31:33 SparrowsV1 systemd[1]: Started gunicorn daemon.
May 17 03:31:34 SparrowsV1 gunicorn[14011]: [2020-05-17 03:31:34 +0000] [14011] [INFO] Starting gunicorn 20.0.4
May 17 03:31:34 SparrowsV1 gunicorn[14011]: [2020-05-17 03:31:34 +0000] [14011] [INFO] Listening at: unix:/run/guniMay 17 03:31:34 SparrowsV1 gunicorn[14011]: [2020-05-17 03:31:34 +0000] [14011] [INFO] Using worker: sync
May 17 03:31:34 SparrowsV1 gunicorn[14011]: [2020-05-17 03:31:34 +0000] [14033] [INFO] Booting worker with pid: 140May 17 03:31:34 SparrowsV1 gunicorn[14011]: [2020-05-17 03:31:34 +0000] [14038] [INFO] Booting worker with pid: 140May 17 03:31:34 SparrowsV1 gunicorn[14011]: [2020-05-17 03:31:34 +0000] [14039] [INFO] Booting worker with pid: 140
其他消息来源建议我编辑我的默认 nginx 配置文件,在位置 /api/ 块上没有 (http://)
proxy_pass unix:/run/gunicorn.sock;
此更改引发错误
[emerg] 14127#14127: invalid URL prefix in /etc/nginx/sites-enabled/defaul
我想我已经用尽了所有可能的链接来解决这个问题,所以欢迎任何帮助。
【问题讨论】:
标签: django nginx gunicorn digital-ocean