urb
urb

Reputation: 964

Nginx permission denied

I want to deploy my flask service in a server with centOS 7. So I followed this tutorial - https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uwsgi-and-nginx-on-centos-7 .

After runnning systemctl start nginx command, I got this error:

nginx: [emerg] bind() to 0.0.0.0:5000 failed (13: Permission denied)

My nginx.conf file:

server {
    listen 5000;
        server_name _;
        location / {
                include uwsgi_params;
                uwsgi_pass unix:/root/fiproxy/fiproxyproject/fiproxy.sock;
        }
    }

Note: flask service and wsgi work ok. And I've tried to run nginx with superuser and the error remains.

Upvotes: 2

Views: 4985

Answers (2)

urb
urb

Reputation: 964

After search a lot in Internet, I found a solution to my problem.

I ran this command to get all used ports in my machine: semanage port -l. After that, I filtered the output with: semanage port -l | grep 5000.

I realized that this port 5000 is used by commplex_main_port_t, I searched in speedguide and I found: 5000 tcp,udp **UPnP**.

Conclusion, maybe my problem was bind a standard port.

To add your desired port use this command:

sudo semanage port -a -t http_port_t  -p tcp [yourport]

Now run nginx with sudo:

sudo systemctl stop nginx
sudo systemctl start nginx

Upvotes: 4

Jianjian Yang
Jianjian Yang

Reputation: 1234

The Nginx master process needs root permission. Because it needs bind port.
You need start Nginx under root user.
Then you can define the user of child processes in nginx.conf.

Upvotes: 1

Related Questions