首页 > 解决方案 > 在 Ubuntu 上通过 Apache Web 服务器和 DAV 启用 Subversion 访问

问题描述

我有一个 Ubuntu 20 在我的家庭网络上的 PC 上运行,我想在本地网络上用作我家中的 Subversion 服务器。我安装了 Apache Web 服务器和 Subversion,现在我想使用 HTTP DAV 协议通过 Apache Web 服务器添加访问权限。

我打算在 Windows PC 上使用带有 Ankh 插件的 Visual Studio,并在 Ubuntu 服务器上使用 Subversion 来存储我的源代码存储库。

当前修改 Apache 配置以启用使用 HTTP 访问 Subversion 的方法是什么?到目前为止,我发现的方向似乎对信息有点轻,只不过是一系列要使用的命令,并且由于某种原因它们看起来很旧。

在我看来,由于我支持本地网络上的单个用户,我需要:

https://192.168.0.4/svn/完成上述操作后,假设我的 Ubuntu 服务器位于192.168.0.4本地家庭网络上的 IP 地址,我应该能够使用 Visual Studio 的 Ankh 插件使用 URL 访问我的 Subversion 存储库。

我目前在哪里:

Apache 和 Subversion 的版本是:

rick@rick-MS-7B98:/etc/apache2/mods-enabled$ apache2 -version
Server version: Apache/2.4.41 (Ubuntu)
Server built:   2020-08-12T19:46:17

rick@rick-MS-7B98:/etc/apache2/mods-enabled$ svn --version
svn, version 1.13.0 (r1867053)
   compiled Mar 24 2020, 12:33:36 on x86_64-pc-linux-gnu

我在文件夹中找到了/etc/apache2/mods-enabled一个文件,该文件dav_svn.conf似乎是 DAV 通过 Apache 访问 Subversion 的配置文件。该文件包含:

rick@rick-MS-7B98:/etc/apache2/mods-enabled$ cat dav_svn.conf
# dav_svn.conf - Example Subversion/Apache configuration
#
# For details and further options see the Apache user manual and
# the Subversion book.
#
# NOTE: for a setup with multiple vhosts, you will want to do this
# configuration in /etc/apache2/sites-available/*, not here.

# <Location URL> ... </Location>
# URL controls how the repository appears to the outside world.
# In this example clients access the repository as http://hostname/svn/
# Note, a literal /svn should NOT exist in your document root.
#<Location /svn>

  # Uncomment this to enable the repository
  #DAV svn

  # Set this to the path to your repository
  #SVNPath /var/lib/svn
  # Alternatively, use SVNParentPath if you have multiple repositories under
  # under a single directory (/var/lib/svn/repo1, /var/lib/svn/repo2, ...).
  # You need either SVNPath or SVNParentPath, but not both.
  #SVNParentPath /var/lib/svn

  # Access control is done at 3 levels: (1) Apache authentication, via
  # any of several methods.  A "Basic Auth" section is commented out
  # below.  (2) Apache <Limit> and <LimitExcept>, also commented out
  # below.  (3) mod_authz_svn is a svn-specific authorization module
  # which offers fine-grained read/write access control for paths
  # within a repository.  (The first two layers are coarse-grained; you
  # can only enable/disable access to an entire repository.)  Note that
  # mod_authz_svn is noticeably slower than the other two layers, so if
  # you don't need the fine-grained control, don't configure it.

  # Basic Authentication is repository-wide.  It is not secure unless
  # you are using https.  See the 'htpasswd' command to create and
  # manage the password file - and the documentation for the
  # 'auth_basic' and 'authn_file' modules, which you will need for this
  # (enable them with 'a2enmod').
  #AuthType Basic
  #AuthName "Subversion Repository"
  #AuthUserFile /etc/apache2/dav_svn.passwd

  # To enable authorization via mod_authz_svn (enable that module separately):
  #<IfModule mod_authz_svn.c>
  #AuthzSVNAccessFile /etc/apache2/dav_svn.authz
  #</IfModule>

  # The following three lines allow anonymous read, but make
  # committers authenticate themselves.  It requires the 'authz_user'
  # module (enable it with 'a2enmod').
  #<LimitExcept GET PROPFIND OPTIONS REPORT>
    #Require valid-user
  #</LimitExcept>

#</Location>

标签: apachesvnwebdav

解决方案


/etc/apache2/mods-enabled/dav_svn.conf需要修改文件,创建 Subversion 存储库,并重新启动 Apache Web 服务器,以便允许通过 Apache Web 服务器访问 Subversion 存储库。

首先检查位于目录中的dav*文件(dav.loaddav_svn.loaddav_svn.conf)的必要符号链接/etc/apache2/mods-available是否在目录中/etc/apache2/mods-enabled,因为只有.conf.load列出的文件/etc/apache2/mods-enabled将在 Apache 启动时被处理。

该文件dav_svn.conf指定有关 Apache 服务器查找正确目录以及如何执行用户身份验证所需的 Subversion 存储库的信息。这些.load文件指示 Apache 需要加载哪些库才能以编程方式访问存储库。所需的库位于libapache2-mod-svnapt install.

注意:在尝试删除和清理 Subversion 和 Apache 安装以重新安装它们之后,我在处理这个问题时遇到了一个问题apt和错误。重新安装后使用 Subversion 服务器启动 Apache Web 服务器时,dpkg请参阅“未知 DAV 提供程序:svn”,这是我在 askubuntu stackexchange 中发布的一个帖子,目的是寻求帮助。

dav_svn.conf我使用的文件如下:

rick@rick-MS-7B98:/etc/apache2/mods-enabled$ cat dav_svn.conf
# dav_svn.conf - Example Subversion/Apache configuration
#
# For details and further options see the Apache user manual and
# the Subversion book.
#
# NOTE: for a setup with multiple vhosts, you will want to do this
# configuration in /etc/apache2/sites-available/*, not here.

# <Location URL> ... </Location>
# URL controls how the repository appears to the outside world.
# In this example clients access the repository as http://hostname/svn/
# Note, a literal /svn should NOT exist in your document root.
<Location /svn>

  # Uncomment this to enable the repository
  DAV svn

  # Set this to the path to your repository
  SVNPath /srv/svn
  # Alternatively, use SVNParentPath if you have multiple repositories under
  # under a single directory (/var/lib/svn/repo1, /var/lib/svn/repo2, ...).
  # You need either SVNPath or SVNParentPath, but not both.
  #SVNParentPath /var/lib/svn

  # Access control is done at 3 levels: (1) Apache authentication, via
  # any of several methods.  A "Basic Auth" section is commented out
  # below.  (2) Apache <Limit> and <LimitExcept>, also commented out
  # below.  (3) mod_authz_svn is a svn-specific authorization module
  # which offers fine-grained read/write access control for paths
  # within a repository.  (The first two layers are coarse-grained; you
  # can only enable/disable access to an entire repository.)  Note that
  # mod_authz_svn is noticeably slower than the other two layers, so if
  # you don't need the fine-grained control, don't configure it.

  # Basic Authentication is repository-wide.  It is not secure unless
  # you are using https.  See the 'htpasswd' command to create and
  # manage the password file - and the documentation for the
  # 'auth_basic' and 'authn_file' modules, which you will need for this
  # (enable them with 'a2enmod').
  AuthType Basic
  AuthName "Subversion Repository"
  AuthUserFile /etc/apache2/dav_svn.passwd
  Require valid-user

  # To enable authorization via mod_authz_svn (enable that module separately):
  #<IfModule mod_authz_svn.c>
  #AuthzSVNAccessFile /etc/apache2/dav_svn.authz
  #</IfModule>

  # The following three lines allow anonymous read, but make
  # committers authenticate themselves.  It requires the 'authz_user'
  # module (enable it with 'a2enmod').
  #<LimitExcept GET PROPFIND OPTIONS REPORT>
    #Require valid-user
  #</LimitExcept>

</Location>

修改文件后,我使用命令sudo systemctl restart apache2重新启动 Apache2 Web 服务器,一切都很好。

我必须创建在文件指令中/etc/apache2/dav_svn.passwd指定的密码文件。AuthUserFiledav_svn.conf

我正在使用文件指令中/srv/svn指定的标准 Subversion 存储库路径。我使用该命令创建存储库。SVNPathdav_svn.confsudo svnadmin create /srv/svn

接下来,我使用该sudo svn mkdir命令创建了现有 Subversion 存储库(、、和)的目录树trunkreleasebranches需要复制这些目录树,以便将svnadmin loadSubversion 转储文件加载到我的新存储库中。请参阅如何导出(然后导入)Subversion 存储库?

安装新的 SSD 以通过 samba 和 webDAV 使用

我想在我的 Ubuntu 20.04 PC 上添加一个新的 500GB 三星 SSD 以获得额外的文件服务器空间,以允许使用 samba 在我的 LAN 上共享文件以允许 Windows 网络驱动器和通过运行在 Apache2 网络服务器上的 webDAV 服务器访问Ubuntu 电脑。

我做的第一件事是将新的 500GB 三星 EVO 860 SSD 安装到盒子中并启动它。

接下来我必须为 Linux 格式化驱动器,创建mount点,然后通过在/etc/fstab.

我选择的挂载点是/srv/ssda,samba 和 webDAV 之间共享的文件夹是一个文件夹public,所以共享区域的路径是/srv/ssda/public. 我还决定ssda在 samba 共享Ssda和 webDAV 路径的名称中使用ssdadav.

我选择了/srv作为根目录,而不是/mnt因为我已经在使用一个文件夹来/srv进行 samba 共享。

接下来,我修改了 samba 配置文件/etc/samba/smb.conf,在我之前创建的现有 samba 文件共享下添加了新文件夹共享的定义,并重新启动了 samba。

[Ssda]
path = /srv/ssda/public
browsable =yes
writable = yes
guest ok = yes
read only = no
create mask = 644

接下来,我修改了 Apache2 配置文件/etc/apache2/sites-enabled/000-default.conf,并在现有的 webDAV 条目和附加的 webDAV 条目下添加了AliasDirectory指令,使用的路径与我用于 samba 共享的路径相同。我重新启动了 Apache。

    Alias /ssdadav /srv/ssda/public

    <Directory /srv/ssda/public>
        DAV On
    </Directory>

此时,我可以坐在 Windows 10 PC 和Map network drive...新 SSD 上,并在那里创建一个简单的文本文件。然后使用 URL 打开 Ubuntu PC 上的 Apache 服务器的浏览器,http://192.168.0.4/ssdadav/并在文件列表中查看文本文件并在浏览器中打开它。


推荐阅读