user12551055
user12551055

Reputation:

docker nginx port 80 permission denied on ubuntu 16

My host machine is on aws lightsail ubuntu 16.

Everything working working in my local machine but on aws ubuntu 16.

I facing the error: nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)

This is my Dockerfile for nginx:

FROM nginxinc/nginx-unprivileged:1-alpine

COPY ./default.conf /etc/nginx/conf.d/default.conf
COPY ./uwsgi_params /etc/nginx/uwsgi_params

USER root

RUN mkdir -p /vol/static
RUN chmod 755 /vol/static

USER nginx

is there anyone know how to solve the problem?

Upvotes: 3

Views: 12789

Answers (2)

Thomas Dwyer III
Thomas Dwyer III

Reputation: 141

You can add the CAP_NET_BIND_SERVICE capability to nginx so it can bind to reserved ports:

setcap cap_net_bind_service=+ep /usr/local/nginx/sbin/nginx

Then port 80 should work just fine. You'll need to ensure your nginx is built in a way that does not require setting LD_LIBRARY_PATH though, since this will prevent that from working. If you are using LD_LIBRARY_PATH, add the path(s) you need to /etc/ld.so.conf or /etc/ld.so.conf.d/nginx.conf instead (and don't forget to run ldconfig afterwards).

Upvotes: 0

anemyte
anemyte

Reputation: 20286

Saving my comment as an answer in case someone will stumble into this as well.

TCP/IP port numbers below 1024 can not be taken by unprivileged users. You are using an unprivileged version of NGINX and so you cannot bind port 80. That is why for this image the default port is 8080 instead of 80 (readme link).

You still should be able to use port 80 with this image if you are not using host network mode (docker run --net host).

Upvotes: 8

Related Questions