2017-08-26 72 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