0

I am trying to host my website and CMS on the same Ubuntu server and am trying to access them both, but I am struggling with the configuration. The website is currently a simple HTML page, and the CMS is a Node app. The CMS app has an index page on http://localhost:1337/ and a dashboard page on http://localhost:1337/admin. With my current setup I can only view the index page on WEBSITE.eu/admin. When I try to go to WEBSITE.eu/admin/admin it is unable to find the static files (json / js files, etc.) to render the page.

So in short what I want to do is: WEBSITE.eu/admin location to point to http://localhost:1337/admin so the CMS dashboard is shown.

My current server block config

server {
        listen 80;
        listen [::]:80;

        root /var/www/WEBSITE/html;
        index index.html index.htm;

        server_name WEBSITE.eu www.WEBSITE.eu;

        location /admin {
                proxy_pass http://localhost:1337/admin/;
                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;
        }
}

Thanks in advance.

sandervspl
  • 1
  • 1
  • 1
  • 1
    `proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade';` are probably useless in your case – Antony Gibbs Mar 09 '19 at 20:09
  • `proxy_pass http://localhost:1337$request_uri;` should work fine in your case – Antony Gibbs Mar 09 '19 at 20:14
  • and now you need to find what files are required out of /admin/ for the admin to be usable ( /img/ /css/ /vendor/ etc...) and proxy pass those too – Antony Gibbs Mar 09 '19 at 20:15
  • Try: `proxy_pass http://localhost:1337;` – Richard Smith Mar 09 '19 at 20:45
  • @AntonyGibbs Do you happen to have an example? In my network tab I see my .js files are being downloaded but parsing the .js files is still going wrong. This only happens when I do the proxy on `/admin`. When I proxy `/` it all works fine. – sandervspl Mar 09 '19 at 21:42
  • @RichardSmith Same thing as my reply above happens. – sandervspl Mar 09 '19 at 21:44
  • 3
    If you are trying to proxy `/admin/` to `/`, you should use `location /admin/` (with a trailing `/`) and `proxy_pass http://localhost:1337/;` (also with a trailing `/`) – Richard Smith Mar 09 '19 at 21:48
  • As Richard pointed out this `location /admin/ { proxy_pass http://localhost:1337/admin/; ...` should work – Antony Gibbs Mar 10 '19 at 22:33
  • @RichardSmith thanks alot, the trailing slash in proxy_pass was also my problem. But why is it behaving like that, can I read anything about it somewhere in the docs? – 0x45 Oct 22 '22 at 02:22
  • 1
    @0x45 see the [official docs](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass), particularly the sections "If the proxy_pass directive is specified with a URI" and "If proxy_pass is specified without a URI". – Richard Smith Oct 22 '22 at 08:59

0 Answers0