Description: Here I have explain, How to setup tomcat, deploy multiple application and setup nginx as reverse proxy for tomcat application.
Setup:
- Install tomcat on port 8080 with 2 sample application
- Install Nginx on port 80 and 443 to serve as a reverse proxy
- 34.222.157.147 Public IP address of the machine
<tomcat-users> <role rolename="manager-gui" /> <user username="manager" password="admin" roles="manager-gui" /> <role rolename="admin-gui" /> <user username="admin" password="admin" roles="manager-gui,admin-gui" /> </tomcat-users>
- application1.local == http://34.222.157.147:8080/SampleWebApp
- application2.local == http://34.222.157.147:8080/sample
server { listen 80; server_name application1.local; } server { listen 443 http2 ssl; server_name application1.local; ssl_certificate /etc/ssl/application1/application1.crt; ssl_certificate_key /etc/ssl/application1/application1.key; access_log /var/log/nginx/application1-access.log; error_log /var/log/nginx/application1-error.log; location = / { return 301 https://application1.local/SampleWebApp/; } location / { proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:8080; } }
server { listen 80; server_name application2.local; } server { listen 443 http2 ssl; server_name application2.local; ssl_certificate /etc/ssl/application2/application2.crt; ssl_certificate_key /etc/ssl/application2/application2.key; access_log /var/log/nginx/application2-access.log; error_log /var/log/nginx/application2-error.log; location = / { return 301 https://application2.local/sample/; } location / { proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:8080; } }
After setting up both the vhost, need to setup either self signed or upload purchased SSL and upload to respective location.