From http to https I can no longer access my nodejs app

February 14, 2017 426 views
Nginx Node.js MongoDB Ubuntu 16.04

I keep gettin error of: Cannot GET //v1/foodtruck after chaing from http tp https:

1 Answer

@codeperfect

If you would, please post your server block so we can take a look -- that includes everything between server { and the closing }.

  • @jtittle here is the server block as requested. Many thanks.

    server {
    listen 80 defaultserver;
    listen [::]:80 default
    server;
    return 301 https://$host$requesturi;
    }
    server {
    listen 443;
    server
    name nerdwithatwist.com;

        ssl on;
        # Use certificate and key provided by Let's Encrypt:
    
        ssl_certificate /etc/letsencrypt/live/nerdwithatwist.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/nerdwithatwist.com/privkey.pem;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_ciphers 'AADECJ+OMHGTR:EDH+AESGCM:AES256+JHTCG:OPECHYT+AOQ';
    
    
        location / {
    
        try_files $uri $uri/ =400;
    
        }
    
        location /api {
                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:3010;
                proxy_ssl_session_reuse off;
                proxy_set_header Host $http_host;
                proxy_cache_bypass $http_upgrade;
                proxy_redirect off;
        }
    

    }

    • @codeperfect

      Since NGINX is responding on 443 without any issues (I see the standard NGINX page but secured), that would lead me to believe it's an issue with how your application is handling the request that's being proxied.

      There's nothing in the server block that indicates that NGINX would have trouble proxying the request or handling it in general, so you'd need to see if there's something app-specific when it comes to handling routes.

      • @jtittle What amuses is that this issue started after i implemented ssl, i mean from http to https. Is there a way i can role back to using http? I have thesame app running localling on my pc without any issue. Could it be the ssl i implemented that is causing this issue. cos when i perform a http get with post, all i see is Cannot GET //v1/foodtruck.
        Many thanks for your support.

        • @codeperfect

          I'd start by making a backup of the above file, so you're not having to fill it in again should you want to swap back. You could then replace the server block you posted with:

          server {
              listen 80 default_server;
              listen [::]:80 default_server;
          
              server_name nerdwithatwist.com;
          
              location / {
          
                  try_files $uri $uri/ =404;
          
              }
          
              location /api {
                      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:3010;
                      proxy_ssl_session_reuse off;
                      proxy_set_header Host $http_host;
                      proxy_cache_bypass $http_upgrade;
                      proxy_redirect off;
              }
          }
          

          and then restart NGINX.

Have another answer? Share your knowledge.