2010-03-19 73 views
7

我在運行Apache + Subversion和後面Nginx上代理SSL的問題,我希望有人可能有答案。我搜索谷歌幾個小時尋找我的問題的答案,似乎無法弄清楚。我看到的是當嘗試使用subversion進行MOVE或COPY時出現的「502(Bad Gateway)」錯誤;然而,結賬和提交工作正常。以下是相關部分的(我認爲)nginx的和Apache的配置文件中的問題:502網關錯誤nginx的+ APACHE +顛覆+ SSL(SVN COPY)

Nginx的

upstream subversion_hosts { 
    server 127.0.0.1:80; 
} 


server { 
     listen  x.x.x.x:80; 
     server_name hostname; 

     access_log /srv/log/nginx/http.access_log main; 
     error_log /srv/log/nginx/http.error_log info; 

     # redirect all requests to https 
     rewrite ^/(.*)$ https://hostname/$1 redirect; 
} 

# HTTPS server 
server { 
     listen  x.x.x.x:443; 
     server_name hostname; 

     passenger_enabled on; 
     root /path/to/rails/root; 

     access_log /srv/log/nginx/ssl.access_log main; 
     error_log /srv/log/nginx/ssl.error_log info; 

     ssl     on; 
     ssl_certificate  server.crt; 
     ssl_certificate_key server.key; 

     add_header Front-End-Https on; 

     location /svn { 
       proxy_set_header Host $host; 
       proxy_set_header X-Real-IP $remote_addr; 
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 

       set $fixed_destination $http_destination; 
       if ($http_destination ~* ^https(.*)$) 
       { 
        set $fixed_destination http$1; 
       } 
       proxy_set_header Destination $fixed_destination; 

       proxy_pass http://subversion_hosts; 
     } 
} 

阿帕奇

Listen 127.0.0.1:80 
<VirtualHost *:80> 
     # in order to support COPY and MOVE, etc - over https (443), 
     # ServerName _must_ be the same as the nginx servername 
     # http://trac.edgewall.org/wiki/TracNginxRecipe 
     ServerName hostname 
     UseCanonicalName on 

     <Location /svn> 
       DAV svn 
       SVNParentPath "/srv/svn" 
       Order deny,allow 
       Deny from all 
       Satisfy any 
       # Some config omitted ... 
     </Location> 

     ErrorLog /var/log/apache2/subversion_error.log 

     # Possible values include: debug, info, notice, warn, error, crit, 
     # alert, emerg. 
     LogLevel warn 

     CustomLog /var/log/apache2/subversion_access.log combined 
</VirtualHost> 

從什麼,同時研究我可以告訴這個問題,服務器名稱必須在apache服務器上以及我所做的nginx服務器上匹配。此外,即使我將配置更改爲僅使用http,該問題似乎仍然存在。

回答

1

我發現我的問題的原因不是nginx和apache之間的代理,而是Apache本身的一個問題。

我在原始問題中沒有提到的是# Some config omitted中的內容。此塊包含下列內容:使用Redmine's認證處理

AuthType Basic 
AuthName "Redmine SVN Repository" 
Require valid-user 
PerlAccessHandler Apache::Authn::Redmine::access_handler 
PerlAuthenHandler Apache::Authn::Redmine::authen_handler 

對於suberversion,我控制用戶訪問。在打開和關閉選項並縮小問題範圍後,我瞭解到他們的身份驗證模塊不是線程安全的。我遇到了錯誤,因爲Apache使用了Worker MPM。切換到Prefork MPM(Ubuntu中的sudo aptitude install apache2-mpm-prefork)解決了這個問題。

8

我今天遇到了這個確切的問題。

添加在apache2的配置下面固定它:

RequestHeader edit Destination ^https http early

乾杯,
 伊尼亞斯中號


來源:

+0

我曾試圖在過去,但想通它再次值得一試。不幸的是,對我來說,這並沒有辦法。 – 2010-03-26 13:42:22

+0

我不得不運行'sudo a2enmod headers',那麼它工作得很好! – 2014-01-28 16:33:38

+0

我增加了這條線,但它不適用多年。今天我刪除了這一行,它現在可以工作 – marstone 2016-05-26 02:11:08

7

以前的解決方案並沒有爲我工作,我不得不改變nginx的配置,並添加在location塊以下的proxy_pass指令之前:

set $fixed_destination $http_destination; 
if ($http_destination ~* ^https(.*)$) { 
    set $fixed_destination http$1; 
} 
proxy_set_header Destination $fixed_destination; 
proxy_set_header Host $http_host; 
+0

這是行得通的,但請你解釋一下這段代碼實際上做了什麼? – bviktor 2017-02-08 10:31:48

+0

目標標題用於COPY和MOVE方法(https://tools.ietf.org/html/rfc2518#page-54)。如果我們使用nginx提供SSL/TLS並將Apache與mod_dav_svn用作後端,則後者不知道https:// URI。通過這段代碼,我們從目標標頭中的https中刪除s,以匹配Apache/Subversion提供的服務。主機頭設置爲來自客戶端的原始HTTP_HOST值。 – Clemens 2017-02-18 16:44:15

+0

非常感謝 – bviktor 2017-02-19 20:28:59