62

I am trying to run Nginx, but I am getting the error below:

bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket in a way forbidden by its access permissions)

Please provide some help on what changes I need to do to make it working?

I have tried running on ports other than 80 and it works. but I need it to be running on 80.

Note: I am running on Windows 7 with command prompt running as Administrator.

Sagar
  • 1,115
  • 2
  • 13
  • 22
  • Possible duplicate of [(ubuntu) nginx: \[emerg\] bind() to 0.0.0.0:80 failed (13: permission denied)](http://stackoverflow.com/questions/18480201/ubuntu-nginx-emerg-bind-to-0-0-0-080-failed-13-permission-denied) – LF00 Sep 20 '16 at 06:01

8 Answers8

81

If the port is already in use, you can change the default port of 80 to a different port that is not in use (maybe 8070). In conf\nginx.conf:

server {
    listen       8070;
    ...
}

After startup, you should be able to hit localhost:8070.

Daniel Treiber
  • 1,411
  • 12
  • 9
28

tl;dr

netsh http add iplisten ipaddress=::

Faced similar issue. Run the above command in command prompt.
This should free up port 80, and you'd be able to run nginx.

Description:
netsh http commands are used to query and configure HTTP.sys settings and parameters.

add iplisten : Adds a new IP address to the IP listen list, excluding the port number.
"::" means any IPv6 address.

For more netsh http commands refer the netsh http commands documentation.

Hope this helps!!

Vishal R
  • 1,279
  • 1
  • 21
  • 27
  • how can we access both IIS and nginx with 80 port, because i required both. if that is not possible suggest me that how can we access an application without port number like for example we nginx is listening on port 8080 then the url is "localhost:8080". instead of that i want to access like www.somename.com @Vishal R – Midhunsai Aug 19 '20 at 15:56
  • you cannot run two servers on single port simultaneously. Start IIS on different port and then reverse proxy it using nginx. refer this: https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/ – Vishal R Aug 19 '20 at 20:22
  • @Midhunsai hope this helps! – Vishal R Aug 20 '20 at 16:42
  • 1
    `netsh http add iplisten ipaddress=::` what does this command do? – Sam Sirry Oct 10 '20 at 11:52
  • 1
    You should also include a simple explanation for the command instead of "run this and it works". – cdalxndr Nov 22 '20 at 20:52
9
nginx: [emerg] bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket in a way forbidden by its access permissions)

I got a similar problem, My 80 port was listening to IIS (windows machine). Stopping IIS freed up 80 port.

The problem got resolved...!!

  • That may solve the problem but i recommend you to change the port at nginx.conf because if you restart your pc, you need always to stop it – Akhdan Rasiq Jan 29 '20 at 04:43
  • You can mark the "World Wide Web Publishing" service to Start Manually, so that IIS does not start on restart. – Adarsha Feb 23 '21 at 18:03
7

You have to be admin or root to bind port 80. Something you can do if you cannot run as root, is that your application listens to other port, like 8080, and then you redirect messages directed to 80 to 8080. If you are using Linux you redirect messages with iptables.

rodolk
  • 5,606
  • 3
  • 28
  • 34
  • Sorry for not mentioning the details about operating system. I am using windows and running command prompt as administrator. Please provide any way to solve this on windows. Thanks rodolk. – Sagar Sep 20 '16 at 08:45
5

Please check if another Proxy is running under port 80 ---> in my case IIS was running as a reverse proxy, so nginx could not start..

Stopping IIS, and starting of NGXIN solved the problem

Mili Be
  • 53
  • 1
  • 3
4

My Tomcat server was running on port 80. Changed the port number in conf\nginx.conf file and it started to work.

pavithraCS
  • 709
  • 6
  • 23
2

This is an old question but since I had this problem recently I thought of posting another possible reason in this problem.

If the user is using Docker and has already tried all proposed solutions as stated above and is wondering why port 80 is trying to bind although on your configurations you are overwriting the port to non root port e.g. listen 8080; it seems that the newer NGINX images have a default nginx.conf file in /etc/nginx/conf.d.

Sample:

$ grep -r 80 /etc/nginx/
/etc/nginx/conf.d/default.conf:    listen       80;

On my case I removed it on my Dockerfile:

RUN set -x \
        && rm -f /etc/nginx/nginx.conf \
        && rm -f /etc/nginx/conf.d/default.conf

Next step pass from my custom configurations:

COPY ["conf/nginx.conf", "/etc/nginx/nginx.conf"]
Thanos
  • 1,618
  • 4
  • 28
  • 49
1

For future Googlers:

My problem was with port 443 when using nginx with ssl. I figured out that xampp was automatically running it's apache, mysql, and filezilla via system services. After uninstalling xampp, the problem is solved.

Studocwho
  • 2,404
  • 3
  • 23
  • 29