如何使用Apache2设置WebDAV在OpenSUSE 12.2上

如何使用Apache2在OpenSUSE 12.2上设置WebDAV

本指南介绍如何在OpenSUSE 12.2服务器上使用Apache2设置WebDAV。 WebDAV代表基于Web的分布式创作和版本控制 ,是HTTP协议的一组扩展,允许用户直接编辑Apache服务器上的文件,以便不需要通过FTP下载/上传文件。 当然,WebDAV也可以用来上传和下载文件。

我不会保证这将为您工作!

1初步说明

我在这里使用IP地址为192.168.0.100的OpenSUSE 12.2服务器。

2安装WebDAV

如果Apache尚未安装,请按如下方式进行安装:

zypper install apache2

然后启用WebDAV模块:

a2enmod dav
a2enmod dav_fs
a2enmod dav_lock

然后为Apache创建系统启动链接并启动它:

systemctl enable apache2.service
systemctl start apache2.service

3创建虚拟主机

我现在将在目录/ srv / www / web1 / web中创建Apache vhost www.example1.com 。 如果您已经拥有要启用WebDAV的虚拟主机,则必须根据您的情况调整本教程。

首先,我们创建目录/ srv / www / web1 / web ,并使Apache用户( wwwrun )和组( www )是该目录的所有者:

mkdir -p /srv/www/web1/web
chown wwwrun:www /srv/www/web1/web

现在我们为www.example1.com创建Apache vhost:

vi /etc/apache2/vhosts.d/www.example1.com.conf
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName www.example1.com
        ServerAlias example1.com

        DocumentRoot /srv/www/web1/web/
        <Directory /srv/www/web1/web/>
                Options Indexes MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

</VirtualHost>

打开/etc/apache2/httpd.conf ,并在Include /etc/apache2/vhosts.d/*.conf行之前添加NameVirtualHost行:

vi /etc/apache2/httpd.conf
[...]
### Virtual server configuration ############################################
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs-2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
NameVirtualHost *:80

Include /etc/apache2/vhosts.d/*.conf
[...]

然后重新启动Apache:

systemctl restart apache2.service

4配置WebDAV的虚拟主机

现在我们使用用户测试创建了WebDAV密码文件/srv/www/web1/passwd.dav (如果-c开关创建的文件不存在):

htpasswd2 -c /srv/www/web1/passwd.dav test

您将被要求输入用户测试的密码。

(如果/srv/www/web1/passwd.dav已经存在,请不要使用-c开关,因为这将从头开始重新创建文件,这意味着丢失该文件中的所有用户!)

现在我们更改/srv/www/web1/passwd.dav文件的权限 ,以便只有rootwww组的成员可以访问它:

chown root:www /srv/www/web1/passwd.dav
chmod 640 /srv/www/web1/passwd.dav

现在我们在/etc/apache2/vhosts.d/www.example1.com.conf中修改我们的vhost www.example1.com ,并添加以下行:

vi /etc/apache2/vhosts.d/www.example1.com.conf
[...]
        Alias /webdav /srv/www/web1/web

        <Location /webdav>
           DAV On
           AuthType Basic
           AuthName "webdav"
           AuthUserFile /srv/www/web1/passwd.dav
           Require valid-user
       </Location>
[...]

Alias指令(与<Location>一起)使得当您调用/ webdav时,调用WebDAV,但仍可以访问vhost的整个文档根目录。 该vhost的所有其他URL仍然是“正常”的HTTP。

最终的vhost应该是这样的:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName www.example1.com
        ServerAlias example1.com

        DocumentRoot /srv/www/web1/web/
        <Directory /srv/www/web1/web/>
                Options Indexes MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        Alias /webdav /srv/www/web1/web

        <Location /webdav>
           DAV On
           AuthType Basic
           AuthName "webdav"
           AuthUserFile /srv/www/web1/passwd.dav
           Require valid-user
       </Location>
</VirtualHost>

接下来,我们必须指定WebDAV锁数据库的位置。 我想要在/ var / lib / dav /中创建该目录:

mkdir /var/lib/dav/
chown wwwrun:www /var/lib/dav/

打开/etc/apache2/httpd.conf并在NameVirtualHost *上方添加一个DAVLockDB指令:80行:

vi /etc/apache2/httpd.conf
[...]
### Virtual server configuration ############################################
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs-2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
<IfModule mod_dav_fs.c>
# Location of the WebDAV lock database.
DAVLockDB /var/lib/dav/lockdb
</IfModule>
NameVirtualHost *:80

Include /etc/apache2/vhosts.d/*.conf
[...]

之后重新启动Apache:

systemctl restart apache2.service

5测试WebDAV

我们现在将安装cadaver ,一个命令行WebDAV客户机:

zypper install cadaver

要测试WebDAV是否工作,请输入:

cadaver http://www.example1.com/webdav/

应提示您输入用户名。 输入测试 ,然后输入用户测试的密码。 如果一切顺利,您应该被授予访问权,这意味着WebDAV工作正常。 键入退出以离开WebDAV shell:

server1:~ # cadaver http://www.example1.com/webdav/
Authentication required for webdav on server `www.example1.com':
Username: test
Password:
dav:/webdav/> quit
Connection to `www.example1.com' closed.
server1:~ #

您现在可以开始使用WebDAV,如本教程第6章和第7章所述, 如何在Ubuntu 9.10上使用Apache2设置WebDAV 。 WebDAV URL是http://www.example1.com/webdav/对于Linux客户端和http://www.example1.com:80 / webdav / Windows客户端。

6链接

赞(52) 打赏
未经允许不得转载:优客志 » 系统运维
分享到:

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏