【发布时间】:2017-10-13 02:15:01
【问题描述】:
我已经在我的服务器上使用 docker 内的 nginx 设置了一个反向代理,从那时起所有请求都重定向到 https,尽管我没有将所有位置都设置为 https 重定向。
基本上我想要的是能够使用反向代理同时提供 https 和 http。 此外,我希望能够动态重定向到不同的 URI,例如,我想将 /bla2/foo/bar 的所有路由设置为仅重定向到 /bla2 之后的内容 我试图在这里得到的是,每当访问 example.com/bla2/foo/bar 它应该将其重定向到 example.com/foo/bar 而没有 bla2 部分...
- 可以在同一个配置文件上吗?
- 什么会导致我的服务器将所有请求重定向到 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,并被重定向到不同的路径。
【问题讨论】:
-
现在有什么问题?还有什么在3004上运行? NodeJS?
-
我有 2 个不同的问题,一个是无论我是否指向应用程序都将所有 http 重定向到 http,另一个是我上面提到的路由问题。我刚刚编辑了内容,希望现在更清楚。是的,这些应用程序是节点 js 应用程序
-
如果您直接在浏览器中访问
http://example.com:3004/并重定向到 https,那么这可能只是因为您的应用正在发送该重定向。还要确保清除浏览器缓存 -
我的配置是否符合我的要求?
-
从外观上看,我没有看到任何问题,它应该做你想做的事
标签: redirect docker nginx reverse-proxy