Boot and angular front-end applications are running on docker containers. I do own a domain and with Nginx reverse proxy to pass the requests for appropriate front-end, back-end which is spring-boot. Default 80 is serving my front-end for more clarification.
Pre details:
Sample domain : xyz.com
Front-end app : running on default port 80
Back-end spring-boot app: running on port 8085
First part of my Nginx configuration:
server {
listen 80;
listen [::]:80;
server_name xyz.com;
location / {
root /var/www/site;
try_files $uri $uri/ /index.html;
location /api{
proxy_pass http://localhost:8085;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header connection "upgrade";
}
}
When I type xyz.com my website is up and running and some front-end routes:
: xyz.com/blogs
: xyz.com/images
: xyz.com/news
These are my rest routes in springboot back-end:
: xyz.com/api/article/getAll
: xyz.com/api/public/mail/sendmail
The interesting part is I can't serve my backend application which is running on port 8085.
This means whenever my URL comes with /api/* it should go to port 8085 but in my case it says "404 not found".
Why are my rest routes not working, did I miss something in my Nginx configuration?
Note: Spring boot container is working fine no issues in docker or application, I think the problem is from Nginx configuration particularly location block.
The block is serving the / first followed by the /api. This should be reversed and then things will work normally.
server {
listen 80;
listen [::]:80;
server_name xyz.com;
location /api{
proxy_pass http://localhost:8085;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header connection "upgrade";
}
location / {
root /var/www/site;
try_files $uri $uri/ /index.html;
}
}
I had the same issue and got it resolved that way. Refer to NGINX reverse proxy for multiple locations not working for more help.