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

71👍

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 that 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;

These parameters are used to forward information to the application that you’re proxying to. I’ve worked with an old CentOS server that didn’t have a proxy_params file, Instead of creating one myself, I just included these parameters directly; and 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)

3👍

In my case, I had a file named myproject in the directory /etc/nginx/sites-enabled. But I had no file named myproject in the directory /etc/nginx/sites-available. And I do not need that myproject file actually, as I didn’t create that intentionally.

So I just deleted the myproject file from the /etc/nginx/sites-enabled directory using sudo rm myproject and voila! Now sudo nginx -t was successful!

1👍

When installing nginx on ubuntu, normally, there is proxy_params and the path is /etc/nginx/proxy_params. But your ubuntu doesn’t have it, so making proxy_params or adding the code which proxy_params has are good solutions as danidee answered.

This time, I made the docker container which has nginx and alpine which is one of the linux distributions. But it doesn’t have proxy_params same as the old CentOS that danidee worked with. So I added the code of proxy_params which is the simpler way than making proxy_params.

It seems like some linux distributions or some old linux distributions may not have proxy_params.

In addition, I’ve seen the tutorial you use before. For nginx configuration, you better make only one myproject.conf at /etc/nginx/conf.d/myproject.conf(Don’t forget .conf after myproject. The file without .conf cannot be found by nginx). In this case, you don’t need to make two files at /etc/nginx/sites-available/myproject and /etc/nginx/sites-enabled/myproject.

Leave a comment