Spring Boot and Nginx integration
This works for me. Can you try this?
-
Running tomcat
docker run -d -p 8080:8080 --name=tomcat tomcat:8
-
Running nginx
docker run -d -p 80:80 --link tomcat:tomcat --name=nginx nginx
-
Go inside nginx container and update the conf
docker exec -it nginx bash
/etc/nginx/nginx.conf:
server { listen 80 default_server; server_name subdomain.domain.com; location / { proxy_pass http://tomcat:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } }
-
Restart nginx service
nginx -s reload
-
Access the tomcat through nginx from host browser. You may need to add entry to /etc/hosts
http://subdomain.domain.com
Complete nginx conf: nginx.conf
Sam
Updated on July 11, 2022Comments
-
Sam almost 2 years
In my project, web app is developed using Spring boot with default tomcat server. I am using NGINX as load-balancer and have configured my spring-boot-web-app in NGINX configuration as follows:
location /spring-boot-web-app { proxy_pass http://spring-boot-web-app/ } http { upstream /spring-boot-web-app { server <IP_of_spring_boot_app>:<Port_of_spring_boot_app> } }
Now lets say NGINX IP and port as nginx_ip and nginx_port respectively. Also working URL for my web app as: http://web_app_ip:web_app_port/rest/echo/hi
The above URL works fine. But when i try to hit same URI via NGINX it throws 404. URL used via NGINX as: http://nginx_ip:nginx_port/spring-boot-web-app/rest/echo/hi
Is there something i am missing?
-
Sam about 8 yearsReally appreciate your help "Gangaraju". But the docker command you proposed i cant use. Because i am using consul to do it and define dependency.
-
Gangaraju about 8 yearsIt may not fit into your environment. But try to debug your issue, by comparing with these steps and check what you are missing. I would suggest you to run these containers in other environment to cross verify the nginx configuration/ for better understanding
-
Sam about 8 yearsThank you very much Gangaraju for your prompt help..Really appreciate!1
-
Sam about 8 yearsAccepted the answer as it gave some route to debug. Will post the solution once i get it.