Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  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?

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading