DarkIce
DarkIce

Reputation: 47

HTTPS with Nginx and Nodejs

So I used certbot to configure Nginx for https. That worked well (I used the automatic configuration).

Now how can I configure my Node.js back end to be able to make GET/POST requests from the front end that is being hosted with Nginx?

EDIT:

location /api {
proxy_pass http://localhost:3000; #server port
    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;
    }

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;
    }

Upvotes: 1

Views: 876

Answers (1)

Aditya_Anand
Aditya_Anand

Reputation: 565

If you have correctly configured your Nginx with SSl and your node application. The requests you send should work with https://URL . Please check your nginx.conf and verify the following things.

You can add ssl cert in Nginx with

ssl_certificate  /etc/nginx/ssl/server.crt #cert location
  ssl_certificate_key /etc/nginx/ssl/server.key #key location

in your server block in Nginx.And your nodejs App should be configured like this in the server block

 location / {
    proxy_pass http://localhost:3000; #server port
    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;
  }

This will be sufficient for your server to work with SSL.

Upvotes: 1

Related Questions