I have an application running at http://192.168.0.2:8080/
. The main index.html page is located in the /web
directory and it fetches static files, such as css, from the /css
folder.
My aim is to use nginx
as a reverse proxy to redirect myapp.mydomain.com
to my application.
In my current nginx.conf
configuration, I have:
server {
listen 80;
server_name myapp.mydomain.com;
satisfy any;
location / {
proxy_pass http://192.168.0.2:8080/web/;
index index.html index.htm;
}
}
Unfortunately, this setup does not work for fetching css
files as it expects them to be in the /web/css
path.
To work around this issue, I adjusted my nginx.conf
by removing the /web
path like so:
server {
listen 80;
server_name myapp.mydomain.com;
satisfy any;
location / {
proxy_pass http://192.168.0.2:8080/;
index index.html index.htm;
}
}
With this modification, I need to access http://myapp.mydomain.com/web
each time.
However, I would prefer to simply request http://myapp.mydomain.com/
and let nginx
handle the routing.
I believe that implementing something similar to the below snippet could potentially solve my issue, but I haven't been able to figure out how:
location ~ .(css|img|js)/(.+)$ {
try_files $uri /$uri /$1/$2;
}
location / {
proxy_pass http://192.168.0.2:8080/web/;
index index.html index.htm;
}
Below is my complete configuration file, which also includes authentication settings:
upstream app { server 192.168.0.2:8080; }
server {
listen 80;
server_name myapp.mydomain.com myapp.myOtherDomain.com;
satisfy any;
allow 192.168.0.0/24;
deny all;
auth_basic "closed site";
auth_basic_user_file /etc/nginx/auth/passwords;
location / { proxy_pass http://app/web/; }
location /css { proxy_pass http://app; }
location /img { proxy_pass http://app; }
location /js { proxy_pass http://app; }
}
If anyone has any suggestions on how I can resolve this issue, I would greatly appreciate it.
Thank you.