I have a server with this setup:
In the root (/var/www) folder I have an index.html
that links to angular app1 and app2
\index.html
|
+-\app1\index.html
|
+-\app2\index.html
My angular app2 has data in the URL
so my URL
will look like this:
https://www.example.com/app2/thispartisdata/AlongDataStringThatContainsData
When I browse to https://www.example.com/app2
everything works fine
When I browse to https://www.example.com/app2/somedata
this goes to a 404
message from NGINX
I have tried the try_files
configuration option but I only need it for my second app.
So what I would like to do is something like this (but I can't figure out or find what the syntax would be or if it's even possible)
location /app2 {
try_files $uri $uri/ /app2/index.html;
}
I can't get the above to work. I want to have requests to app2 pass the entire URL
on to app2 and not have NGINX
get in the way and return a 404
. I can't find the correct way to have ONLY app2 receive the full URLs and redirect that full URL
to app2's index.html
.
Edit
My full configuration:
server {
server_name example.com www.example.com;
location /app1/api/ {
proxy_pass https://127.0.0.1:5001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /app2/api/ {
proxy_read_timeout 300s;
proxy_connect_timeout 75s;
proxy_pass https://127.0.0.1:5002/;
proxy_http_version 1.1;
proxy_request_buffering off;
proxy_buffering off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# I want to do something like this here, but this give a 500 error
#
# location /app2 {
# try_files $uri /app2/index.html;
# }
location / {
root /var/www;
index index.html;
}
ssl_stapling on;
ssl_stapling_verify on;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name example.com www.example.com;
listen 80;
return 404; # managed by Certbot
}