nginx在两个不同的端口上接受HTTP和HTTPS请求

我有一个nginx服务器设置(两个configuration文件)与两个gunicornnetworking服务器设置和运行。 一个炮弹是生产,另一个是升级。

我想要nginx服务http请求xyz.com以及https请求xyz.com到生产gunicorn服务器@ 127.0.0.1:8000。

我已经完成了这个:

server { listen 80; server_name xyz.com; return 301 https://$http_host$request_uri; } server { listen 443 ssl; server xyz.com; ..... <<< ssl stuff location /{ .... proxy_stuff proxy_pass http://127.0.0.1:8000; } } 

我也希望HTTPstream量到xyz.com:8080和HTTPSstream量到xyz.com:8080到达临时服务器@ 127.0.0.1:8081。 我一直可以得到httpsstream量xyz.com:8080工作如下:

 server { listen 8080 ssl; server_name xyz.com; ...... << ssl stuff location / { ...... << proxy stuff proxy_pass http://127.0.0.1:8081; } } 

但我似乎无法find一个方法来redirect在xyz.com:8080 HTTPstream量在xyz.com:8080 httpsstream量。 我尝试了与端口80相同的redirect,但是没有成功。

可以使用一些方向。

根据你所说的,你想在端口8080上听http和https,我不相信这是可能的。 为不同的端口设置不同的服务器块,在里面的位置块可以有相同的proxy_pass传递到你喜欢的任何地方。

这可能是最接近你所说的,这是听8080 HTTP,8081 HTTPS,并从HTTP转发到HTTPS。 重写可能不完全正确,但你明白了。

 server { listen 8080; # HTTP server_name example.com; rewrite ^ https://example.com:8081$request_uri? redirect; # rewrite ^ https://example.com:8081 redirect; # Alternate rewrite } server { listen 8081 ssl; server_name example.com; ...... << ssl stuff location / { ...... << proxy stuff proxy_pass http://127.0.0.1:8081; } }