【问题标题】:502 Bad Gateway with nginx + apache + subversion + ssl (SVN COPY)502 Bad Gateway with nginx + apache + subversion + ssl (SVN COPY)
【发布时间】:2011-01-29 13:51:12
【问题描述】:

我在 Nginx 代理后面使用 SSL 运行 Apache + Subversion 时遇到问题,我希望有人能找到答案。我已经在谷歌上搜索了几个小时来寻找我的问题的答案,但似乎无法弄清楚。尝试使用颠覆进行移动或复制时,我看到的是“502(坏网关)”错误;但是,签出和提交工作正常。以下是有问题的 nginx 和 apache 配置文件的相关部分(我认为):

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,这个问题似乎仍然存在。

【问题讨论】:

    标签: svn apache ssl nginx


    【解决方案1】:

    我今天遇到了这个问题。

    在 apache2 配置中添加以下内容修复它:

    RequestHeader edit Destination ^https http early

    干杯,
    伊格纳斯M


    来源:

    【讨论】:

    • 我过去曾尝试过,但认为值得再试一次。对我来说不幸的是,这并没有奏效。
    • 我添加了这一行,但它多年来无法正常工作。今天我删除了这条线,它现在可以工作了
    • 虽然这是一个可行的建议,但这不是一个正确的建议。更正确的是教 nginx 根据更改的方案发送固定的 Destination 标头。
    【解决方案2】:

    以前的解决方案对我不起作用,我不得不更改 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;
    

    【讨论】:

    • 这确实有效,但您能解释一下这段代码的实际作用吗?
    • Destination 标头用于 COPY 和 MOVE 方法 (tools.ietf.org/html/rfc2518#page-54)。如果我们使用 nginx 提供 SSL/TLS 并使用带有 mod_dav_svn 作为后端的 Apache,后者不知道 https:// URI。通过这个 sn-p,我们从 Destination 标头中的 https 中去除 s 以匹配 Apache/Subversion 所服务的内容。 Host 标头设置为来自客户端的原始 HTTP_HOST 值。
    • 非常感谢朋友
    【解决方案3】:

    我发现问题的原因不是 nginx 和 apache 之间的代理,而是 Apache 本身的问题。

    我在原始问题中没有提到的是# Some config omitted 中的内容。该块包含以下内容:

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

    对于颠覆,我使用Redmine's 身份验证处理程序控制用户访问。在打开和关闭选项并缩小问题范围后,我了解到他们的身份验证模块不是线程安全的。我遇到了错误,因为 Apache 正在使用 Worker MPM。切换到 Prefork MPM(Ubuntu 中的sudo aptitude install apache2-mpm-prefork)解决了这个问题。

    【讨论】:

      【解决方案4】:

      就我而言,我使用的是 RouixSVN,我只需要清除我计算机上的 SVN 身份验证数据,然后再次登录即可有效。希望对其他人有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-06-14
        • 2023-03-20
        • 2014-03-27
        • 2020-06-12
        • 2018-04-23
        • 2021-02-24
        • 1970-01-01
        • 2022-08-16
        相关资源
        最近更新 更多