0

I am using a simple "hello world" Express.JS (8080 port) application deployed in Ubuntu Server, with NGINX reverse proxy setup as below.

The application working well for http port but not for https port

  • nginx version: nginx/1.10.3 (Ubuntu)
  • OpenSSL 1.0.2g 1 Mar 2016

And my configuration file is like this:

server {
        listen 80;
        listen 443 default ssl;
        server_name localhost;

         ssl_certificate /root/mydir/ssl/certificate.crt;
         ssl_certificate_key /root/mydir/ssl/private.key;

    location / {
                proxy_pass http://localhost:8080;
                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;
        }
}

The configuration is working fine for http connection for my domain testdomain.com, but completely failing for https://testdomain.com or https://www.testdomain.com

What went wrong with this configuration?

SSL certs are generated by sslforfree.com.

halfer
  • 19,824
  • 17
  • 99
  • 186
Kiran
  • 1,145
  • 1
  • 8
  • 22

1 Answers1

1
server {
  listen       80;
   server_name example.com;

   # force redirect http to https
   rewrite ^ https://$http_host$request_uri? permanent;    
}

server {
  listen 443;
   ssl on;
   ssl_certificate /root/mydir/ssl/certificate.crt;
   ssl_certificate_key /root/mydir/ssl/private.key;
   server_name example.com;

   proxy_pass         http://127.0.0.1:8000;
   proxy_set_header   Host $host;
   proxy_set_header   X-Real-IP $remote_addr;
   proxy_set_header   X-Forwarded-Proto https;
   ....
 }
Sergiu
  • 2,928
  • 3
  • 27
  • 37
  • Hi still i am getting the error site cannot be reached, and now even http also not working plz help – Kiran Sep 27 '17 at 19:13
  • To make http work remove # force redirect http to https rewrite ^ https://$http_host$request_uri? permanent; What the logs are saying? – Sergiu Sep 27 '17 at 19:19
  • nginx access.log is empty , it not moving :-( – Kiran Sep 28 '17 at 04:41
  • Have a look at: https://stackoverflow.com/questions/42761992/configuring-https-for-express-and-nginx – Sergiu Sep 28 '17 at 06:37
  • thank you for helping me , my issue is resolved now, i didnt notice 443 port is close. now enabled its working fine. – Kiran Sep 28 '17 at 08:40
  • I'm glad your issue has been resolved and you're welcome – Sergiu Sep 28 '17 at 08:43