-2

I can't restart nginx because I got [emerg] 6594#6594: bind() to 0.0.0.0:443 failed (98: Address already in use). How does multiple server block work? Without the staging server block my config is working fine.

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    server_name api.example.com;

    location / {
        proxy_pass http://localhost:3001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

server {
    listen 443;

    server_name staging-api.example.com;

    location / {
        proxy_pass http://localhost:3002;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}
Alisa T Morgan
  • 667
  • 1
  • 7
  • 12
  • The error says that Address already in use. Which mean there is a process which is already using that port 443. Find the process which is using that port kill it and try starting nginx again! – Mukesh Verma Sep 29 '18 at 14:59
  • @MukeshVerma what is port 443 actually? – Alisa T Morgan Sep 29 '18 at 16:16
  • 1
    Possible duplicate of [Nginx will not start (Address already in use)](https://stackoverflow.com/questions/42303401/nginx-will-not-start-address-already-in-use) – Alexander Azarov Sep 29 '18 at 16:48
  • 443 Port is a reserved port which is used for https connections just like 80 is used by normal http connection!! – Mukesh Verma Sep 30 '18 at 05:43

1 Answers1

0

netstat -anp | grep :443 chgeck which app take over the port 443,and if not necessary, kill it and then restart nginx

tyloafer
  • 123
  • 7