I am completely new to nginx and I am trying to set something up so that it is possible to navigate from an existing application on a remote server to a node application. The node app will be on the same server. For now, everything is local on my own machine and I have fired up a simple nginx instance with it's default index page, i.e., navigating to https://localhost
will render the default Welcome to Nginx
page. I would like to be able to navigate to my node app with https://localhost/app
, where the app
part of the url is just an alias. There is no app
directory in reality. Is this possible?
Currently if I run localhost:3000
in my browser, it will redirect to localhost:3000/login
if the user is not authenticated. Therefore https://localhost/app
should also redirect to https://localhost/app/login
and so on. I just cannot get this to work as I'm getting 404s with the server trying to request static resources with app
in the uri i.e, .../public/app/css
. It should be .../public/css
. Same for js and images. So obviously my alias is not working. My config is as follows:
upstream nodeapp {
server localhost:3000;
}
server {
listen 80;
listen [::]:80;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
include snippets/snakeoil.conf; # Temp cert for testing
location /app/ {
alias /home/path/to/public;
proxy_pass http://nodeApp;
proxy_http_version 1.1;
proxy_set_header Upgrade websocket;
proxy_set_header Connection upgrade;
}
I have looked at lots of similar questions and tried various configurations, but I'm completely out of ideas now. Any help would be most appreciated!
EDIT: if I add a slash to the end of proxy_pass proxy_pass http://nodeApp/;
It redirects to localhost/login
where I get a 404 as obviously there is no page set up there. Would I really have to add a location for every route in my node app? There must be a way of doing this. :-/