I am trying to setup Nginx reverse proxy for tomcat application docker containers. I have app1 and app2 listening on host port 8028 and 8030( inside containers bind on 8080). and Nginx and docker setup is on different servers.
192.168.1.10 => nginx => example.com
192.168.1.20:8028/app1 => tomcat app1 (doker container)
192.168.1.20:8030/app2 => tomcat app2 (doker container)
and now trying to set up a proxy to access the app as
- https://example.com/app1 => proxy to 192.168.1.20:8028/app1
- https://example.com/app1 => proxy to 192.168.1.20:8030/app2
Now the problem is tomcat redirectPort is set to "443". and which is creating redirection loops. If I access the same tomcat app with apache and ajp connector it is accessible. but there are multiple applications and want to set up a central proxy server.
Below is the configuration
upstream backend1 {
server 192.168.1.20:8028;
}
upstream backend2 {
server 192.168.1.20:8030;
}
server {
listen 80;
server_name example.com;
access_log /var/log/nginx/example.com-access.log ;
error_log /var/log/nginx/example.com-error.log ;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto https;
large_client_header_buffers 4 256k;
location /app1 {
proxy_pass http://backend1/app1;
}
location /app2 {
proxy_pass http://backend2/app2;
}
#return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name example.com;
large_client_header_buffers 4 256k;
access_log /var/log/nginx/example.com-access.log ;
error_log /var/log/nginx/example.com-error.log ;
ssl_client_certificate /etc/nginx/conf/ssl/ca.crt;
ssl_certificate /etc/nginx/conf/ssl/apache.crt;
ssl_certificate_key /etc/nginx/conf/ssl/apache.key;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto https;
location /app1 {
proxy_pass http://backend1/app1;
}
location /app2 {
proxy_pass http://backend2/app2;
}
}