防止重定向到HTTPS和URI黑客我已经设置好的反向代理我里面泊坞窗的nginx服务器上nginx的反向代理

问题描述:

,从那以后,所有的请求重定向到https,虽然我没有设置到HTTPS重定向所有位置。防止重定向到HTTPS和URI黑客我已经设置好的反向代理我里面泊坞窗的nginx服务器上nginx的反向代理

基本上我想要的是能够服务HTTPS和HTTP与反向代理。 此外,我希望能够动态地重定向到不同的URI,比如我想设置/ bla2 /富/酒吧的所有路由重定向到只有什么来后/ bla2 什么,我试图让这里的是,每当访问到example.com/bla2/foo/bar它应该重定向它没有bla2部分example.com/foo/bar ...

  1. 是否有可能同一个配置文件?
  2. 什么能引起我的服务器重定向所有请求到HTTPS

这是我的服务器nginx.conf

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; 
     } 
} 

我希望能够得到直接的内容http://example.com:3004如果我把它放在浏览器中,没有任何重定向到https。 只有当我尝试访问example.com/bla2我希望它需要HTTPS而不是HTTP,和被重定向到不同的路径。

+0

什么是问题的权利吗?还有什么是在3004上运行?的NodeJS? –

+0

我有两个不同的问题,一个是所有http重定向到http无论我指向一个应用程序,另一个路由问题,正如我上面提到的。我只是编辑了内容,我希望它现在更清晰。是的,这些应用程序是节点js应用程序 – user4860092

+1

如果您直接在浏览器“http://example.com:3004 /'中访问并且重定向到https,那么它可能只是因为您的应用程序正在发送该重定向。另外请确保您清除浏览器缓存 –

你需要使用正则表达式捕获组此

location ~* /bla2/(.*) { 
    return 301 http://example.com:3004$1$is_args$args; 
} 

这样做将只使用重写

rewrite ^/bla2/(.*)$ http://example.com:3004/$1 redirect; 

如果你想它透明代理的example.com:3004去除的另一种方式/bla2那么你应该使用

​​

/bla2/http://example.com:3004/斜线/在这里非常重要

+0

如果你不介意添加第三个选项,而不使用重定向,所以我能接受的答案,因为最终我选用不使用重定向的选择,我想你明白我的意思 – user4860092

+0

@ user4860092,现在检查 –