2017-08-26 66 views
0

我需要配置nginx,它充当我的站点(myportal.com)的反向代理。 nginx可以通过squid代理连接到实际的站点。如何配置nginx作为站点的反向代理,这是鱿鱼代理的后台

client - > nginx - > Squid Proxy - > web服务器。

备注:

a。客户端假设nginx为myportal.com的Web服务器。

b。 nginx通过squid代理从实际服务器(myportal.com)获取内容。

谢谢塔伦。当目标Web服务器可直接访问时,我们已成功将nginx配置为反向代理。但是,连接到网络服务于鱿鱼后面。我们正面临着问题。因为客户端必须连接到nginx,假设它是目标服务器(因此没有发送代理标头)。 -

我们也尝试了以下。

upstream @squid { 
    server localhost:3128; 
} 

server { 
    listen 80; 
    server_name relay.example.com; 

    location/{ 
     proxy_pass http://@squid/$scheme://$host$uri; 

     proxy_set_header Host $host; 
     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 Request-URI $request_uri; 

     proxy_redirect off; 
    } 
} 
+0

向我们展示你已经尝试了什么配置,什么问题你正面临 –

+0

编辑问题和更新的代码,不要粘贴在这里命令 –

+0

@TarunLalwani ..任何建议? – user1819071

回答

0

给一个尝试这种配置,它使用的Nginx作为反向代理和缓存,也许可以帮助你得到一个想法:

... 
    proxy_buffering on; 
    proxy_cache_path /home/cache levels=1:2 keys_zone=myportal:256m max_size=5g inactive=24h use_temp_path=off; 
    proxy_buffer_size 8k; 
    proxy_buffers  8 24k; 

    server { 
     listen  80; 
     server_name _; 

     location/{ 
      proxy_cache myportal; 
      proxy_cache_use_stale updating error timeout invalid_header http_500 http_502 http_503 http_504; 
      proxy_cache_revalidate on; 
      proxy_cache_min_uses 1; 
      proxy_cache_lock on; 
      proxy_cache_valid 200 301 304 2d; 
      proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie; 

      proxy_redirect off; 
      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 Host myportal.tld; 
      proxy_set_header Connection ""; 
      proxy_http_version 1.1; 
      proxy_pass https://myportal.tld/; 
     } 
    } 
    ... 
+0

感谢@nbari。当目标Web服务器可以直接访问(来自nginx),但是如果它位于鱿鱼后面时,反向代理配置工作正常。我们正面临问题 – user1819071

+0

我的猜测是你需要检查'proxy_set_header Host myportal.tld;'你遇到了什么问题/错误? – nbari