Home > Blockchain >  Docker and Nginx: port 80 and 403: address already in use
Docker and Nginx: port 80 and 403: address already in use

Time:08-13

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?

CodePudding user response:

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
  • Related