title: nginx reverse proxy working only if port 80 available
body: <p>I hope somebody can help me to solve/understand this issue as I am totally stuck.</p>
  <p>I am a ec2 instance running nginx. This ec2 instance is behind a load balancer.</p>
  <p>My nginx configuration, is to reverse the traffic to an external service hosted on azure.</p>
  <p>But for demonstration purpose lets assume this external service is <code>example.com</code></p>
  <p>all my infra is working, and my nginx configuration files is like this:</p>
  <pre><code># This is the new file
  user www-data;
  worker_processes auto;
  pid /run/nginx.pid;
  
  events {
      worker_connections 768;
      # multi_accept on;
  }
  
  http {
      server_names_hash_bucket_size 128;
      server {
          listen   80; ## listen for ipv4; this line is default and implied
          root /usr/share/nginx/html;
          index index.html;
  
          server_tokens  off; # disable the Server nginx header 
  
          # enable gzip
          gzip on;
          gzip_disable &quot;msie6&quot;;
  
          gzip_comp_level 6;
          gzip_min_length 1100;
          gzip_buffers 16 8k;
          gzip_proxied any;
          gzip_types
              text/plain
              text/css
              text/js
              text/xml
              text/javascript
              application/javascript
              application/x-javascript
              application/json
              application/xml
              application/rss+xml
              image/svg+xml;
  
          location / {
              # try_files $uri /index.html; # redirect all request to index.html
              proxy_pass https://example.com;
  
          }
      }
      server {
          listen   443; ## listen for ipv4; this line is default and implied
          root /usr/share/nginx/html;
          index index.html;
  
          server_tokens  off; # disable the Server nginx header 
  
          # enable gzip
          gzip on;
          gzip_disable &quot;msie6&quot;;
  
          gzip_comp_level 6;
          gzip_min_length 1100;
          gzip_buffers 16 8k;
          gzip_proxied any;
          gzip_types
              text/plain
              text/css
              text/js
              text/xml
              text/javascript
              application/javascript
              application/x-javascript
              application/json
              application/xml
              application/rss+xml
              image/svg+xml;
  
          location / {
              # try_files $uri /index.html; # redirect all request to index.html
              proxy_pass https://example.com;
  
          }
      }
      ##
      # Basic Settings
      ##
  
      sendfile on;
      tcp_nopush on;
      tcp_nodelay on;
      keepalive_timeout 65;
      types_hash_max_size 2048;
      # server_tokens off;
  
      # server_names_hash_bucket_size 64;
      # server_name_in_redirect off;
  
      include /etc/nginx/mime.types;
      default_type application/octet-stream;
  
      ##
      # SSL Settings
      ##
  
      ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
      ssl_prefer_server_ciphers on;
  
      ##
      # Logging Settings
      ##
  
      access_log /var/log/nginx/access.log;
      error_log /var/log/nginx/error.log;
  
      ##
      # Gzip Settings
      ##
  
      gzip on;
      gzip_disable &quot;msie6&quot;;
  
      # gzip_vary on;
      # gzip_proxied any;
      # gzip_comp_level 6;
      # gzip_buffers 16 8k;
      # gzip_http_version 1.1;
      # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
  
      ##
      # Virtual Host Configs
      ##
  
      include /etc/nginx/conf.d/*.conf;
      include /etc/nginx/sites-enabled/*;
  }
  
  
  #mail {
  #   # See sample authentication script at:
  #   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
  # 
  #   # auth_http localhost/auth.php;
  #   # pop3_capabilities &quot;TOP&quot; &quot;USER&quot;;
  #   # imap_capabilities &quot;IMAP4rev1&quot; &quot;UIDPLUS&quot;;
  # 
  #   server {
  #       listen     localhost:110;
  #       protocol   pop3;
  #       proxy      on;
  #   }
  # 
  #   server {
  #       listen     localhost:143;
  #       protocol   imap;
  #       proxy      on;
  #   }
  #}
  </code></pre>
  <p>With this configuration everything works just fine. But if I remove the <code>server</code> on port 80 and keep only the <code>443</code> and reload nginx. On the browser I get the error <code>Bad Gateway</code></p>
  <p>Is the <code>server 80</code> required for nginx? I checked all the documentation and couldn't find anything.</p>
  <p>Please can anyone enlighten me on this issue or just point me on the right path? thank you so much for any help you can provide or hint.</p>
  <p>And please if my question is not 100% clear, don't hesitate to ask for details</p>