apache 如何在命名虚拟主机的根目录中启用 mod_dav_svn?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/264676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 16:56:01  来源:igfitidea点击:

How to enable mod_dav_svn in the root directory of a named virtual host?

svnapache

提问by Matthew Scharley

Is this possible? I had troubles with SVN clients not being able to access the repository with the following error message:

这可能吗?我遇到了 SVN 客户端无法访问存储库并显示以下错误消息的问题:

Repository moved permanently to 'http://svn.example.com/test/'; please relocate

存储库永久移动到“ http://svn.example.com/test/”;请搬迁

If I added the '/' to the end of the path I was trying to access, it just strips it off again, and shows the same error message. My configuration file looks like:

如果我将“/”添加到我尝试访问的路径的末尾,它只会再次将其剥离,并显示相同的错误消息。我的配置文件看起来像:

<VirtualHost *>
  ServerName svn.example.com
  # Normal VirtualHost stuff here

  <Location /svn>
    # Uncomment this to enable the repository
    DAV svn
    SVNParentPath /some/path/to/repositories

    # Setup mod_authz_svn, etc, etc here
  </Location>
</VirtualHost>

Note: This works. But if I change the Location to just /it stops working again with the error above. Is it possible to use the root directory, or am I missing something here? Firefox displays the repository listing fine when serving the repositories out of the root.

注意:这有效。但是,如果我将 Location 更改为 just/它会因上述错误而再次停止工作。是否可以使用根目录,或者我在这里遗漏了什么?当从根目录提供存储库时,Firefox 可以很好地显示存储库列表。

As someone else pointed out, this only seems to be an issue inside named virtual hosts... Anyone have any smart ideas why?

正如其他人指出的那样,这似乎只是命名虚拟主机内部的问题......任何人都有什么聪明的想法为什么?

采纳答案by azkotoki

The problem is that you are using the document root also as the repository root (I'm not blaming you, this should just work, but it doesn't).

问题是您将文档根目录也用作存储库根目录(我不是在责备您,这应该可以正常工作,但它没有)。

Try pointing the DocumentRootand SVNParentPathdirectives to different physical locations, so the resulting config file should look like this (abbreviated):

尝试将DocumentRootSVNParentPath指令指向不同的物理位置,因此生成的配置文件应如下所示(缩写):

<VirtualHost *:80>
    DocumentRoot /home/svn.example.com/docroot

    <Location />
        SVNParentPath /home/svn.example.com/svnroot
        SVNListParentPath on
    </Location>
</VirtualHost>

Also, as @Nigel Jewell says, remove that Rewrite block, for sanity.

另外,正如@Nigel Jewell 所说,为了理智起见,请删除该 Rewrite 块。

回答by yurique

Found this in /etc/apache2/conf.d/subversion.conf (need to map error documents to defaults):

在 /etc/apache2/conf.d/subversion.conf 中找到了这个(需要将错误文档映射到默认值):

<VirtualHost *>
    ServerName svn.example.com
    ErrorLog    /var/log/apache2/svn.example.com-error_log
    TransferLog /var/log/apache2/svn.example.com-access_log
    #
    # Do not set DocumentRoot. It is not needed here and just causes trouble.
    #
    # Map the error documents back to their defaults.
    # Otherwise mod_dav_svn tries to find a "error" repository.
    #
    ErrorDocument 400 default
    ErrorDocument 401 default
    ErrorDocument 403 default
    ErrorDocument 404 default
    ErrorDocument 405 default
    ErrorDocument 408 default
    ErrorDocument 410 default
    ErrorDocument 411 default
    ErrorDocument 412 default
    ErrorDocument 413 default
    ErrorDocument 414 default
    ErrorDocument 415 default
    ErrorDocument 500 default
    ErrorDocument 501 default
    ErrorDocument 502 default
    ErrorDocument 503 default
    #
    <Location />
...
    </Location>

After I've done this everything started working as expected.

完成此操作后,一切都按预期开始工作。

回答by Davide Gualano

Continuing from comments to my previous answer, I've tried also with a VirtualHost:

继续评论我之前的答案,我也尝试过使用 VirtualHost:

<VirtualHost 127.0.0.1:80>
<Location />
    DAV svn
    SVNPath /repository
    AuthType Basic
    AuthName "Repository authentication"
    AuthUserFile /repository/.svn-auth
    AuthzSVNAccessFile /repository/.svn-access
    Satisfy All
    Require valid-user
</Location>
</VirtualHost>

and it's working, I can browse the repository with firefox and can access it with the svn command line client.

它正在运行,我可以使用 Firefox 浏览存储库,并可以使用 svn 命令行客户端访问它。

回答by Davide Gualano

Ok, I think we have found who to blame: named virtual hosts :)

好的,我想我们已经找到了罪魁祸首:命名的虚拟主机:)

With this configuration:

使用此配置:

<VirtualHost dave.test>
<Location />
    DAV svn
    SVNPath /repository
    AuthType Basic
    AuthName "Repository authentication"
    AuthUserFile /repository/.svn-auth
    AuthzSVNAccessFile /repository/.svn-access
    Satisfy All
    Require valid-user
</Location>
</VirtualHost>

when I run the command svn ls http://dave.testI got this error:

当我运行命令时svn ls http://dave.test出现此错误:

svn: Server sent unexpected return value (405 Method Not Allowed) in response to
PROPFIND request for '/'

So apparently there is an issue when one tries to enable mod_dav_svn in the root directory of a named virtual host...

因此,当尝试在命名虚拟主机的根目录中启用 mod_dav_svn 时,显然存在问题...

回答by Matthew Scharley

I ended up using mod_rewrite succesfully to rewrite all access to the root directory into /svn, hence getting access to the repositories from /repository_name. For reference, this is the configuration I ended up with:

我最终成功地使用 mod_rewrite 将所有对根目录的访问重写/svn/repository_name. 作为参考,这是我最终得到的配置:

# Rewrite / into /svn to avoid errors that seem to occur when using the root
# for repositories.
RewriteEngine On
# Subdirectories that SHOULD be accessed directly, ie. trac
# /svn should be here to avoid redirect loops
RewriteCond %{REQUEST_URI} !^/(trac|svn)/
RewriteRule ^/(.*)$ /svn/ [PT]

回答by Davide Gualano

This is working for me:

<Location />
    DAV svn
    SVNPath /repository
    AuthType Basic
    AuthName "Repository authentication"
    AuthUserFile /repository/.svn-auth
    AuthzSVNAccessFile /repository/.svn-access
    Satisfy All
    Require valid-user
</Location>

Pointing the browser to http://127.0.0.1shows me the repository content.

将浏览器指向http://127.0.0.1 会显示存储库内容。

回答by Davide Gualano

Thanks for this, finally got it working with a VirtualHost due to your comments.

谢谢你,由于你的评论,终于让它与 VirtualHost 一起工作。

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName svn.example.com
    ServerAlias svn
    DocumentRoot /home/svn.example.com/public_html

    RewriteEngine On

    RewriteCond %{REQUEST_URI} ^/svn$
    RewriteRule .* /svn/ [PT]

    RewriteCond %{REQUEST_URI} !^/svn/
    RewriteRule ^/(.*)$ /svn/ [PT]

    <Location /svn>
            DAV svn
            SVNParentPath /home/svn.example.com/public_html
            SVNListParentPath on
    </Location>

    <LocationMatch /svn/.+>
            AuthzSVNAccessFile /home/svn.example.com/support/access.cfg

            AuthType Basic
            AuthName "Subversion"
            AuthUserFile /home/svn.example.com/.htpasswd
            Require valid-user
    </LocationMatch>
</VirtualHost>

As shown I found that you probably want to also add:

如图所示,我发现您可能还想添加:

RewriteCond %{REQUEST_URI} ^/svn$
RewriteRule .* /svn/ [PT]

In order to catch http://svn.example.com/svnwithout the ending /.

为了捕获没有结尾 / 的http://svn.example.com/svn

Nige.

尼日。

回答by Davide Gualano

DocumentRoot "/usr/local/apache/htdocs/ForSvn" ServerName xxx.xxx ServerAdmin xxx ErrorLog "/usr/local/apache/logs/xxx-error_log" TransferLog "/usr/local/apache/logs/xxx-access_log"

DocumentRoot "/usr/local/apache/htdocs/ForSvn" ServerName xxx.xxx ServerAdmin xxx ErrorLog "/usr/local/apache/logs/xxx-error_log" TransferLog "/usr/local/apache/logs/xxx-access_log"

ReWriteEngine On
RewriteCond %{REQUEST_URI} ^/svn$
RewriteRule .* /svn/ [PT]

<Location /svn>
       DAV svn
       SVNParentPath /svn/repos
       SVNListParentPath on

       # Limit write permission to list of valid users.
       <LimitExcept GET PROPFIND OPTIONS REPORT>
             AuthType Basic
             AuthName "Subversion"
             AuthUserFile /svn/authfiles/svn-htpasswd
             AuthzSVNAccessFile /svn/authfiles/svn-access.conf
             Require valid-user
       </LimitExcept>
</Location>

<LocationMatch /svn/myProject/>
             AuthType Basic
             AuthName "Subversion (private)"
             AuthUserFile /svn/authfiles/svn-htpasswd
             AuthzSVNAccessFile /svn/authfiles/svn-access.conf
             Require user user1 user2 user3...
</LocationMatch>

and works fine with me. Thank you for this.

和我一起工作得很好。这次真是万分感谢。