title: prevent redirecting to https and URI hacks nginx reverse proxy
body: <p>I have setted up a reverse proxy on my server with nginx inside docker, and since then all request are redirecting to https although i didn't set all locations to https redirection.</p>
  
  <p>Basically what i want is to be able to serve both https and http with the reverse proxy.
  In addition i want to be able to redirect to different URI dynamically, for example i want to set all routes of /bla2/foo/bar to be redirected to only what comes after /bla2
  what i tried to get here is that whenever accessing to example.com/bla2/foo/bar it should redirect it to example.com/foo/bar without the <strong>bla2</strong> section...</p>
  
  <ol>
  <li>Is it possible on the same configuration file?</li>
  <li>what can cause my server to redirect all request to https</li>
  </ol>
  
  <p><strong>This is my server nginx.conf</strong></p>
  
  <pre><code> server {
          listen   443;
          ssl    on;
          ssl_certificate    /etc/ssl/example.com.crt;
          ssl_certificate_key    /etc/ssl/example.com.key;
  
  
          listen     80;
          server_name  example.com;
  
          location /bla/bla {
                  proxy_pass http://example.com:3980/foo/bar1;
          }
  
          **location /bla2/**{
                 # proxy_pass http://example.com:3004;
                  return 301 http://example.com:3004$request_uri;
  
                  proxy_set_header X-Real-IP $remote_addr;
                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                  proxy_set_header Host $http_host;
                  proxy_set_header X-NginX-Proxy true;
                  proxy_redirect off;
                  proxy_http_version 1.1;
                  proxy_set_header Upgrade $http_upgrade;
                  proxy_set_header Connection "upgrade";
  
                  proxy_set_header X-Forwarded-Proto $scheme;
          }
  
          location /app3 {
                  rewrite ^/app3(.*) /$1 break;
                  proxy_pass http://example.com:1236/app3;
          }
  }
  </code></pre>
  
  <p>I want to be able to get directly content of <strong><a href="http://example.com:3004" rel="nofollow noreferrer">http://example.com:3004</a></strong> if i put it in the browser without any redirection to https.
  Only if i try access <strong>example.com/bla2</strong> i want it to be required https instead of http, and to be redirected to different path.</p>