Question

Cannot start nginx due to error: invalid port

I recently updated my Let’s Encrypt certificate. To do so, I had to stop my nginx server. After updating the certficate, I tried starting my nginx server with sudo systemctl start nginx and get this error: nginx: [emerg] invalid port in "[::]:" of the "listen" directive in /etc/nginx/sites-enabled/default:4.

Here is my code for the the default file:

# HTTP — redirect all traffic to HTTPS
server {
    listen 80;
    listen [::]: 80;
    return 301 https://$host$request_uri;
}

# HTTPS — redirects www to non-www
server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name www.atomz.io;

    # Use the Let's Encrypt certificates
    ssl_certificate /etc/letsencrypt/live/atomz.io/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/atomz.io/privkey.pem;

    # Include the SSL configuration from cipherli.st
    include snippets/ssl-params.conf;
    return 301 https://atomz.io$request_uri;
}

# HTTPS — proxy all requests to the Node app
server {
    # Enable HTTP/2
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name atomz.io;

    # Use the Let’s Encrypt certificates
    ssl_certificate /etc/letsencrypt/live/atomz.io/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/atomz.io/privkey.pem;

    # Include the SSL configuration from cipherli.st
    include snippets/ssl-params.conf;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://localhost:3000/;
        proxy_ssl_session_reuse off;
        proxy_set_header Host $http_host;
        proxy_cache_bypass $http_upgrade;
        proxy_redirect off;
    }
}

Thanks for the help!


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

After many hours of debugging and research, I found out that after using cerbot, you need to remove the line listen [::]: 80;. Still don’t know why exactly…

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel