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:
- Installed and configured Nginx, set up the proper folders and configuration file;
- Used Let's Encrypt to generate and place the SSL for the domain;
- Used
forever start server.js
to have the Node application run as a process in the background; - Added the appropriate port rules in
ufw
forserver.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