Question
Nginx - How to serve 404 and static files through private networking?
I’ve followed this tutorial exactly to set up, successfully my Node.Js app: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-14-04
My Node app lives on a separate droplet, as does my Nginx.
I’m redirecting all my www and http traffic to https://domain.com. This all WORKS.
Now I also want to serve custom error files. But they are located in the node app on the other droplet, in the public folder /var/www/app/public. Is there anyway I can serve my 404 file from Nginx, but keep it on the Node.JS droplet?
Same question for my static files (images/fonts), is there a way I can serve my static files from Nginx, but keep them on my Node.js droplet (NOT copy them over to Nginx droplet?)
Thanks
server {
listen 80;
server_name www.domain.com;
return 301 https://domain.com$request_uri;
}
server {
listen 443 ssl;
server_name www.domain.com;
return 301 https://domain.com$request_uri;
ssl_certificate /etc/nginx/ssl/www.domain.com.chained.crt;
ssl_certificate_key /etc/nginx/ssl/www.domain.com.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers AES256+EECDH:AES256+EDH:!aNULL;
ssl_prefer_server_ciphers on;
}
server {
listen 443 ssl;
server_name domain.com;
ssl_certificate /etc/nginx/ssl/www.domain.com.chained.crt;
ssl_certificate_key /etc/nginx/ssl/www.domain.com.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers AES256+EECDH:AES256+EDH:!aNULL;
ssl_prefer_server_ciphers on;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location / {
proxy_pass http://ip_of_node_droplet:4000;
proxy_redirect off;
proxy_http_version 1.1;
}
}
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×