Nginx https reverse proxy another 502
<p>Hi I am trying to setup a nginx to work as a reverse proxy to an application that I am running on a tomcat server. when I try to access my application through http it works fine, but when I try to access it over https I am getting a 502 error</p>

<p>here follows my nginx config file</p>

<pre><code>user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}


http {
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;


    include /etc/nginx/mime.types;
    default_type application/octet-stream;


    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log notice;


    gzip on;
    gzip_disable "msie6";


    rewrite_log on;

     server{
        ssl on;
        listen 80;
        listen 443 ssl;
        server_name myapp.local;

        ssl_certificate max.local.crt;
        ssl_certificate_key server.key;
        #ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
                #ssl_ciphers RC3:HIGH:!aNULL:!MD5;
                #ssl_prefer_server_ciphers on;
                ssl_session_timeout 5m;
        keepalive_timeout 60;



        error_log /var/log/nginx/hybris.log;
        rewrite_log on;

        set $my_port 9001;
        set $my_protocol "http"; 

        if ($scheme = https){
            set $myport 9002;
            set $my_protocol "https";
        }


        location / {    
            if ( $http_user_agent ~ "Chrome"){
                #just a proof of concept
                return 301 http://$host/AE/en;
            }

            if ( $http_user_agent ~ "Firefox"){
                #just a proof of concept
                return 301 http://google.com/;
            }
        }


        location /AE/en {


            proxy_pass $scheme://10.0.2.2:$my_port;
            proxy_set_header Host $host;
        }


        location ~(?:/..)?/_ui/(.*) {
            proxy_pass http://10.0.2.2:9001/_ui/$1;     
            proxy_set_header Host $host;
        }



     }

}
</code></pre>