2010-03-19 65 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