When I visit a website at https//mysite.com:8080
, redirects to the /login
page, and everything works fine.
But as soon as I refresh the page I get an error:
{"statusCode":404,"message":"Cannot GET /login","error":"Not Found"}
How can this be fixed?
server {
listen 8080 ssl;
ssl_certificate /etc/letsencrypt/live/my-site.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/my-site.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/my-site.com/chain.pem;
error_page 497 301 =307 https://my-site.com:8080$request_uri;
server_name my-site.com;
root /home/username/apps/project/client/dist;
index index.html;
location @app {
proxy_pass https://127.0.0.1:9900;
}
location / {
try_files $uri $uri/ @app;
error_page 405 @app;
}
}
CodePudding user response:
Your config looks like a dirty hack to join frontend and backend web apps together. Usually you should differentiate frontend and backend calls according to the URI prefix, something like
location /api/ {
proxy_pass https://127.0.0.1:9900;
}
location / {
try_files $uri $uri/ /index.html;
}
However you can try to use the second dirty hack like this one:
location @app {
proxy_pass https://127.0.0.1:9900;
proxy_intercept_errors on;
error_page 404 = /index.html;
}
location / {
try_files $uri $uri/ @app;
error_page 405 @app;
}
As being said, this is only a hack and better to be avoided due to the performance considerations.