0

I'm just trying to run a nodejs app I made on a proxypass domain, and have it work exactly as it did on my desktop. However, for some reason, even though I defined a seperate document root for this proxypass path, it didn't load the files from it. I've done the exact same thing with my 404 page, and it worked. Here's the page in question: https://jakesandbox.com/iwl which does load the server.js file, which in turn loads the index.html file, but all of the scripts and styles the index references cannot be loaded. Here's my nginx config(with censors):

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        listen 443 ssl default_server;
        listen [::]:443 ssl default_server;
        root /home/ubuntu/FAKE WEB ROOT DIR;
        index index.html index.htm index.php index.nginx-debian.html;
        server_name XXxXX.com;
        error_page 404 /404.html;
        location = /404.html {
                root /home/ubuntu/FAKE ERROR DIR/;
                internal;
        }
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        }
        location ~ /\.ht {
                deny all;
        }
        ssl_certificate /etc/letsencrypt/live/XXxXX.com.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/XXxXX.com.com/privkey.pem;
        location /iwl {
                root /home/ubuntu/FAKE NODEJS DIR/;
                proxy_pass http://localhost:PORT/;
                proxy_ssl_trusted_certificate /etc/letsencrypt/live/XXxXX.com.com/fullchain.pem;
                proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        }
}

P.S. I'm not willing to relocate my nodejs app to my webroot/change paths

  • What URL paths are you having a problem with? Be specific. – Michael Hampton Jan 17 at 16:15
0

If you open up the Network tab on your browser's devtools, you can see that the site is trying to load the assets at the root of the URL. for example:

https://jakesandbox.com/style.css 404

As you don't wish to change the Node.JS paths, you could get around this with an nginx location wildcard, added to the server block:

location ~* \.(js|css)$ {
        root /path/to/your/node/root;   
        expires 30d;
    }

You may need to edit this to include other extensions. I'ved included js and css above.

/path/to/your/node/root should contain the css and js files at that level.

EDIT

I"m running out of time to test this, but yes the location block I posted may catch JS, CSS files at the root of the domain. Can you test and update the comments. This rule may work better:

location ~* ^/iwl/.+\.(js|css|jpg)$ {
    root /path/to/your/node/root;
} 

However I"m having trouble with this myself, as when applied appears to look for /path/to/your/node/root/iwl/style.css meaning you'd have to move anything in your node root to a subdirectory called iwl. If you can afford to make this change then it might be benificial. You could even call the directory static which is the common method used for other frontend sites.

  • 2 questions, first will this impact my existing server config(if so how can I mitigate this)? and also what does expires 30d; do? – Jake t Jan 17 at 17:51
  • expires 30d; actualy came from an example I copied this from. You may wish to leave it there, basically it sets a few headers which tell the browser to keep the file cached, reducing load on your server. This may not be what you want if you're testing the server with new changes to the files effected by this. This answer explains better than me. – v25 Jan 17 at 17:57
  • @Jaket As for the first query I've added a slight edit. – v25 Jan 17 at 19:12
  • hmm... still referencing the same locations... did I do something wrong? Due to comment length restrictions here are the directory structures and the new nginx conf: pastebin.com/it1Cktv1 pastebin.com/1Ez4UsvP (I hit enter by accident sorry) – Jake t Jan 17 at 21:08
  • I think we may be loosing info in obfuscation of private data (which I can understand). your linked directory listing refers to iw not iwl, which may be a copying mistake. Also the nginx config still has my example /path/to/your/node/root in place, which should be changed to lead to the iwl directory. Agree with comment restriction here. Please gist an updated conf and I can help you in the comments there where there's more room. post link back here ;-) – v25 Jan 17 at 21:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.