0

I've been attempting to configure a backend NodeJS server (ExpressJS) to use with Nginx, but there have been some difficulties. I am currently running a DigitalOcean droplet with Ubuntu 20.04 installed.

Here's what I've done:

  1. Installed and configured Nginx, set up the proper folders and configuration file;
  2. Used Let's Encrypt to generate and place the SSL for the domain;
  3. Used forever start server.js to have the Node application run as a process in the background;
  4. Added the appropriate port rules in ufw for server.js which runs on port 60000.

I've tried quite a few different configs to no avail and tried a few of my own after readings through the docs, but this is what I have now, which is based on the working configuration posed in the replies here, which was referenced in other places as a successful configuration:

GNU nano 4.8             domain.com                        
server {

        root /var/www/example.com/html;
        index index.html index.htm index.nginx-debian.html;

        server_name example.com www.example.com;

    listen [::]:443 SSL ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    listen 80;
    listen [::]:80;

    ssl_certificate /etc/letsencrypt/live/example.com/fullcha>
    ssl_certificate_key /etc/letsencrypt/live/example.com/pri>
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Ce>
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Cert>

    location / {
        proxy_pass http://localhost:60000;
        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;
        try_files $uri $uri/ /index.html;
        }
}

The website works just fine, is SSL-enabled, etc. But one page, "Inventory", sends a command to the express server to run a database query upon the page loading. "Loading ..." is what appears until the data is retrieved (as I've coded it), and it hangs there. The express server isn't receiving anything at all, because if it did, the server-side console would display a message, which it isn't. I'm 100% sure it's the Nginx configuration.

Any ideas? Is there something wrong with the configuration?

Edit: The browser console shows four messages:

Blocked loading mixed active content “http://IPADDR:60000/”

The resource from “https://example.com/static/css/main.3a7e5913.css” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).

Source map error: Error: request failed with status 404
Resource URL: https://example.com/static/css/main.3a7e5913.css
Source Map URL: main.3a7e5913.css.map

Source map error: Error: request failed with status 404
Resource URL: https://example.com/static/js/main.0df87846.js
Source Map URL: main.0df87846.js.map
djdomi
  • 1,377
  • 3
  • 10
  • 19
  • What do the developer tools of your browser show for that request? – Gerald Schneider Jun 07 '22 at 13:44
  • I'll update the original post with the results to keep neat formatting. – Jeremy Marino Jun 07 '22 at 13:46
  • That's what I thought. You need to configure your NodeJS backend to generate the correct requests with the reverse proxy. – Gerald Schneider Jun 07 '22 at 13:54
  • Does this answer your question? [How can I forward requests from my web server?](https://serverfault.com/questions/1035016/how-can-i-forward-requests-from-my-web-server) – Gerald Schneider Jun 07 '22 at 13:55
  • See the section `Backend configuration` of the linked answer. – Gerald Schneider Jun 07 '22 at 13:55
  • Yes, this is exactly what I was looking for. It'll take a bit of time to implement, but I'm sure this is the correct answer. Thank you for pointing me in this direction - for some reason it never appeared in any of my searches, or I overlooked it. – Jeremy Marino Jun 07 '22 at 14:03
  • One last question - the location /jenkins/ in the canonical question you referenced - is that supposed to be a route/page on the site? For example, would I write `location /inventory/` if the page using the backend resource is `example.com/inventory`? – Jeremy Marino Jun 07 '22 at 14:06
  • It's the base URL you proxy the requests to. You have configured the proxy for the location `/`, so for you it would be `/`. – Gerald Schneider Jun 07 '22 at 15:47
  • I would say use HTTPS also on the backend it would fix that imho – djdomi Jun 10 '22 at 16:56

0 Answers0