【发布时间】:2017-09-20 06:39:21
【问题描述】:
我正在为我的石墨网络使用 nginx 反向代理。 我的 nginx.conf 看起来有点像这样
server {
listen 8081;
server_name myserver.com;
return 301 https://$host:5000$request_uri;
}
server {
listen 5000 ssl;
server_name myserver.com;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header Host $host;
add_header 'Access-Control-Allow-Methods' 'GET, POST';
add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type';
add_header 'Access-Control-Allow-Credentials' 'true';
# here comes the basic auth, after the options part
auth_basic 'Restricted';
auth_basic_user_file path/to/.htpasswd;
}
ssl on;
ssl_certificate path/to/crt;
ssl_certificate_key path/to/key;
}
我开始在https://host:5000 上使用我的网站,并且我希望将对该网站的任何 http 请求重定向为 https 请求。截至目前,我看到它被重定向到http://host/
这只发生在登录和注销期间。
我看到很多例子,他们使用端口 80 来监听 http 流量,但我不能使用该端口,因为其他一些应用程序已经在使用该端口。
有人可以帮我解决这个问题吗?
【问题讨论】:
-
您是否尝试过将 80 更改为您的服务器在 nginx 服务器设置中侦听的任何端口?
-
我在 conf 文件中进行了我需要的所有更改。这里我为http流量指定了8081端口。
-
8081 上运行的是什么?那是没有收到转发的请求?
-
8081上没有运行任何东西。它的目的是将port5000上的http流量重定向为https