Search code examples
node.jsnginxsails.jsproxypass

How to configure Sailsjs on subfolder using proxypass?


I run Laravel on Nginx server and want to setup Sailjs on subfolder example.com/sailsapp/

In nginx config I have following

location /sailsapp {
    proxy_pass http://localhost:1337;
}

by visiting example.com/sailsapp/ I would expect '/': { view: 'pages/homepage' }, route to load homepage but instead I get 404.

if I change Sailjs '/sailsapp': { view: 'pages/homepage' }, homepage view loads fine, but the problem is that all assets point to example.com and not example.com/sailsapp which is my main issue.

How can I configure sails app, so it would actually know what is the real base of the aplication rather take the top level domain as base.

Thank you


Solution

  • I have figured out how to achieve what I needed.

    In Nginx config I needed to add rewrite, to simply rewrite /sailsapp/(.*) to /$1 This allowed to proxy request correctly.

    location /sailsapp {
            rewrite /sailsapp/(.*) /$1  break;
            proxy_pass http://localhost:1337;
    }
    

    It still didn't help with the assets though.

    To configure auto inject assets on Sails I went to tasks/config/sails-linker.js and changed fileTmpl: '<script src="%s"></script>', to fileTmpl: '<script src="/sailsapp%s"></script>',

    Not sure if I will come across more issues, but this actually allows me to move forward with my app build.