2014-10-11 100 views
0

我正在尋找一些提示如何做我目前想做的事情。nginx反向代理apache2網站:url返回與代理服務器不對應

這裏就是我該做的: 的Nginx服務器代理(srvrp) - >的Apache2(srvdeba)

這裏是nginx的網站srvrp的配置:

server { 
     server_name www.egloff-j-quest-etna.nx; 

     location/{ 
       proxy_pass http://srvdeba.egloff-j-quest-etna.nx; 
       proxy_redirect off; 
       proxy_set_header X-Real-IP $remote_addr; 
       proxy_set_header Host $proxy_host; 
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
       proxy_set_header X-NginX-Proxy true; 
     } 
} 

這裏是配置在srvdeba啓用站點的網站:

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    ServerName www.srvdeba.egloff-j-quest-etna.nx 
    ServerAlias *srvdeba.egloff-j-quest-etna.nx 

    DocumentRoot /opt/wordpress 
    <Directory /> 
      Options FollowSymLinks 
      AllowOverride None 
    </Directory> 
    <Directory /opt/wordpress/> 
      Options Indexes FollowSymLinks MultiViews 
      AllowOverride None 
      Order allow,deny 
      allow from all 
    </Directory> 

    ErrorLog ${APACHE_LOG_DIR}/error.log 
    LogLevel warn 
    CustomLog ${APACHE_LOG_DIR}/access.log combined 
</VirtualHost> 

目前,這是工作,但不完全,問題如下: 當該網站是通過代理服務器加載,網站上所有的鏈接都是這種形式: http://srvdeba.egloff-j-quest-etna.nx 我希望他們對應: www.egloff-J-追求-etna.nx

於是,我想到了有兩種解決方案,第一種解決方案是使用ngx_http_sub_module ,第二種解決方案是配置apache2,以便他知道他正在被代理,並且可以在通過代理服務器完成請求時重寫URL。 srvdeba必須在沒有代理服務器的情況下訪問時才能工作。 所以我需要你告訴我什麼是最好的解決方案!

在此先感謝您的答案。

+0

那麼,我試過ngx_http_sub_module,它根本不工作。也許我做了一些錯誤的事情。現在我將嘗試配置apache2。 – laxa 2014-10-11 15:29:56

回答

0

所以,我很久以前終於找到了這個問題的答案。 我認爲我最好把它分享給你。

問題不是來自Apache或nginx。 問題來自網站生成錯誤的URL,因爲他不知道他是代理。 因此,如果你有類似的問題,你應該確保該網站知道他正在被代理並生成正確的URL來爲客戶端請求工作。