简体   繁体   中英

Docker and Nginx: port 80 and 403: address already in use

I have a VPS server runs on Ubuntu, I am running multiple Django projects with Nginx and Gunicorn.

Recently, I decided to deploy my latest project with Docker.

Everything is working, except the port 80. I can run the website on example.com:1330 but once I change it to 80, I get this error:

  err: ERROR: for nginx  Cannot start service nginx: driver failed programming external connectivity on endpoint project-nginx (a4417bdb121b0afb1e57e11b68dd0eb74f770ed74f654a2722f4cd74121): Error starting userland proxy: listen tcp4 0.0.0.0:80: bind: address already in use
err: Encountered errors while bringing up the project.

Here is a part of my:

  • docker-compose.yml

    nginx: container_name: portfolio-nginx restart: unless-stopped build: ./nginx ports: - "80:80" # doesn't work - "1330:80" # works

  • Nginx

    upstream project { server project-django:8000; }

    server {

     listen 80; server_name example.com; location / { proxy_pass http://project; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; proxy_redirect off; } location /static/ { root /code; } location /media/ { root /code; }

    }

I thought the problem is I have Nginx already running on port 80:

sudo netstat -ntulp | grep 80

Once I kill the process the docker website works on port 80 . But I lose the other Django projects that doesn't run on docker.

Please, any idea?

Your Django project takes port 80, there is 3 main solutions:

  • Launch Django on other port
  • Launch this project on other port
  • Place projects on different subdomains using NGINX

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM