(ubuntu) nginx: [emerg] bind() to 0.0.0.0:80 failed (13: permission denied)

70,005

Solution 1

the socket API bind() to a port less than 1024, such as 80 as your title mentioned, need root access.

here is "Bind to ports less than 1024 without root access"

and another easier way is to run nginx as root.

Solution 2

If you use a port bigger than 1024 with root privilege, but still got this problem, that's may be caused by SELinux:

Check this port, say 8024, in segange port

sudo semanage port -l | grep http_port_t

If 8024 doesn't exist in the port list, add it into segange port

sudo semanage port -a -t http_port_t  -p tcp 8024

###update in 2017.12.22

Sometimes your SELinux is disabled, you need to enforcing it first. Check the status of SELinux by

$ sestatus

More steps can read this wonderful article: https://www.digitalocean.com/community/tutorials/an-introduction-to-selinux-on-centos-7-part-1-basic-concepts

Solution 3

If see this msg after run "nginx -t", you dont have premission run as root "sudo nginx -t"

Solution 4

nginx needs root access. Just use

sudo nginx

next step along with your password

Share:
70,005
user2350858
Author by

user2350858

Updated on October 13, 2021

Comments

  • user2350858
    user2350858 over 2 years

    I need help figuring out the root cause of this permission denied error. What permissions does nginx need? Why is it so complicated?

  • SomeGuyOnAComputer
    SomeGuyOnAComputer about 6 years
    Running the app using sudo seems like a bad idea.
  • Sal Alturaigi
    Sal Alturaigi almost 6 years
    I am genuinely curious if it is safe to sudo nginx or not.
  • Jakpren
    Jakpren over 5 years
    I don't know whether it's safe or not. But, the non-root users should need sudo privileges to start nginx. You can refer below link to know how to secure nginx. digitalocean.com/community/tutorials/…
  • hanshenrik
    hanshenrik almost 4 years
    no, nginx does not need root access. but anything that want to use ports between 0-1024 needs root access, and his nginx was configured to listen on port 80. anything that tries to listen to port 80 needs root access. reconfigure nginx to listen on port 1025 instead, and no root access is needed.