django- nginx: [emerg] open() “/etc/nginx/proxy_params” failed (2: No such file or directory) in /etc/nginx/sites-enabled/myproject:11

老子叫甜甜 提交于 2020-03-17 10:12:35

问题


i try to deploy a django project with Nginx and Gunicorn with this tutorial. i did all to-dos but, when i create /etc/nginx/sites-available/myproject file with below code:

server {
listen 80;
server_name server_domain_or_IP;

location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
    root /home/sammy/myproject;
}

location / {
    include proxy_params;
    proxy_pass http://unix:/home/sammy/myproject/myproject.sock;
 }
}

and then run sudo nginx -t for find errors, i get this error:

nginx: [emerg] open() "/etc/nginx/proxy_params" failed (2: No such file or directory) in /etc/nginx/sites-enabled/myproject:11
nginx: configuration file /etc/nginx/nginx.conf test failed

what's the problem?? and how to solve it? tanx


回答1:


You're getting the path wrong for proxy_params 99% of the time (From my experience), the default location for the proxy_params file is /etc/nginx/proxy_params but this doesn't seem to be the same for you.

The proxy_params file contains the following:

proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

Which are used to forward information to the application you're proxying to, I've worked on an old Centos server that didn't have a proxy_params file, Instead of creating one myself i just included these parameters directly, so my location block looked like this

location / {
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_pass http://unix:/home/sammy/myproject/myproject.sock;
 }

So it's up to you, If the file exists in another location just include it with the right location:

include /path/to/proxy_params

else you can include the params directly in the location block (Like i did above)

Or create one yourself and place it in /etc/nginx (If you want to stick with your current code)



来源:https://stackoverflow.com/questions/42589781/django-nginx-emerg-open-etc-nginx-proxy-params-failed-2-no-such-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!