我需要Nginx Web服务器连接到侦听端口443的https服务器。直接通过Nginx服务器计算机无法访问https服务器,并且到达nginx服务器需要设置http_proxy和https:proxy参数的https:proxy 。
我们之前使用的是Apache,并使用ProxyRemote * http://10.23.45.32:3128参数来实现,它允许apache服务器通过代理服务器连接到远程https服务器。
我们正在从apache转移到Nginx,需要知道如何添加代理规则,以便Nginx服务器可以将请求传递给https服务器。
我为Nginx设置了以下configuration。
server { listen 80; server_name localhost; access_log /var/log/nginx/localhost.access.log; location / { proxy_pass http://localhost:9000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } #below path is working fine location /cities.json { proxy_pass http://hostname.net:8080/cities.json; } #below rule is working fine location /states/ { proxy_pass http://hostname.net:8080; } #below rule is giving 504 gateway timeout error. location /auth { #cannot call https://authenticationserver.net directly and need to go through proxy by setting http_proxy to http://proxy.host.net:3128 proxy_pass https://authenticationserver.net:443; } }
在Apache中,我使用下面的configuration来设置代理:
<VirtualHost *:8000> ServerName hostname.net <Location /balancer-manager> SetHandler balancer-manager Order Deny,Allow Deny from all Allow from all </Location> <Proxy balancer://authncluster> BalancerMember https://target.host.net </Proxy> <Proxy *> Order Allow,Deny Allow From All </Proxy> ProxyRemote * http://proxy.host.net:3128 SSLProxyEngine On ProxyPreserveHost On ProxyPass /balancer-manager ! ProxyPass /authn/ balancer://authncluster/authn/ ProxyTimeout 300 </VirtualHost>
希望这可以帮助。 请让我知道如何在Nginx中进行configuration。
像这样的事情会做到这一点(path将是错误的,因为你的问题似乎没有指出足够的细节。关键是nginxselect最具体的匹配 – 你可以在这里准备好。
location / { proxy_pass http://localhost:9000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } location /otherurl { proxy_pass http://localhost:9001; # etc } location /thirdurl { proxy_pass http://localhost:9002; # etc }