0

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

  1. https://example.com/app1 => proxy to 192.168.1.20:8028/app1
  2. 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;
    }
}
  • I am able to fix the redirection loop issue by adding header proxy_set_header X-SSL-Request 1; – Sunil Bhoi Dec 12 '19 at 10:52
0

I am able to fix this redirection loop using below header in location block.

proxy_set_header X-SSL-Request 1;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.