Wednesday 7 June 2017

Nginx, React, Node & Let's Encrypt... How to point Nginx at my React app

I have a React app that I need to talk to a Node server running on port 5000(via pm2) and be the root directory of my site. The Node server fetches some data from an API and returns it to the client. Right now I have Nginx pointing right at port 5000 (I followed a tutorial to get to this point as a test).

Say my React app is located at /www/ReactApp/dist/, how do I point Nginx at that instead of my Node server on port 5000?

The Node server.js will just run in the background and my React app will make calls to it to get data.

Here is the contents of my /etc/nginx/sites-enabled/default:

# HTTP — redirect all traffic to HTTPS
server {
    listen 80;
    listen [::]:80 default_server ipv6only=on;
    return 301 https://$host$request_uri;
}

# HTTPS — proxy all requests to the Node app
server {
    # Enable HTTP/2
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name myapp.com;

    # Use the Let’s Encrypt certificates
    ssl_certificate /etc/letsencrypt/live/myapp.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/myapp.com/privkey.pem;

    # Include the SSL configuration from cipherli.st
    include snippets/ssl-params.conf;

    location / {
        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:5000/;
        proxy_ssl_session_reuse off;
        proxy_set_header Host $http_host;
        proxy_cache_bypass $http_upgrade;
        proxy_redirect off;
    }
}



via fromspace

No comments:

Post a Comment