ubuntu中apache2搭建webdav服务

发布时间 2023-08-02 14:11:16作者: tros

1.apache2配置文件目录路径:/etc/apache2

说明:

1.1  *-enabled目录中的文件均为*-available目录中的文件链接。

1.2  apache2启动时读取的文件均为*-enabled目录下的配置文件,因此若要某个配置生效,则需要将其链接到对应的enabled目录中。

1.3  ports.conf 配置文件用来配置监听的端口号。

1.4  mods-* 为apache2模块扩展配置。

1.5  sites-* 为站点配置。

 

2.将dav相关的模块扩展配置放开,即将对应的配置文件链接到mods-enabled目录

 

3.创建webdav站点配置文件8090-webdav-video.conf

<VirtualHost *:8090>
    DocumentRoot "/home/ubuntu/Videos/"
    ServerName "localhost"

    #301重定向
    #RedirectMatch permanent ^/(.*) 

    #强制SSL
    #RewriteEngine on
    #RewriteCond %{HTTPS} !=on
    #RewriteRule ^(.*) https://%{SERVER_NAME}$1 [L,R]


    #防盗链
    

    #流量限制
    

    #防火墙配置
    #日志
    #CustomLog "|/usr/local/phpstudy/system/module/rotatelogs /www/admin/localhost_18003/log/apache_access_%Y-%m-%d.log 86400 480" #combined_with_cookie
    ErrorDocument  403  /error/403.html
    ErrorDocument  400  /error/400.html
    ErrorDocument  404  /error/404.html
    ErrorDocument  502  /error/502.html
    ErrorDocument  503  /error/503.html

    #处理PHP
    #<FilesMatch \.php$>
    #    SetHandler "proxy:fcgi://127.0.0.1:5538"
    #</FilesMatch>
    
    #webdav
    DavLockDB "/var/www/DavLock/video_dav_lock"

      # 配置一个虚拟目录
       Alias /  "/home/ubuntu/Videos/"
    #默认首页
    <Directory "/home/ubuntu/Videos/">
        #DirectoryIndex index.php index.html error/index.html
        #AllowOverride All
        
        #开启Dav支持
        Dav On
        
        # 禁止浏览器显示目录,将-Indexes前的减号去掉为允许显示(当index.html不存在时)
        Options -Indexes +FollowSymLinks
        Order Allow,Deny
        Allow from all
            
        # 认证方式,虽然这种方式不安全但可以快速架设成功我们需要的服务
        AuthType Basic
        
        # 这里的名字随意写
        AuthName "admin"
        
        # 非常关键的用户管理文件,windows下使用Apache目录里的/bin/htpasswd.exe 创建
        # htpasswd -c "/var/www/DavLock/video_dav_lock/userfile.pass" admin
        # 输入两次密码就可以了,-c为创建用户 -m则会将旧的记录全部删除 -cm是两个参数一起使用
        AuthUserFile "/var/www/DavLock/video_dav_lock/userfile.pass"
        AuthBasicProvider file
        # 允许userfile.pass里的所有用户访问
        Require valid-user

        #示例  仅允许用户admin访阅
        #Require user admin

        #示例 guest 用户仅允许查看,其他权限全部排除
        #<LimitExcept PUT POST DELETE MOVE OPTIONS>
        #    Require user guest
        #</LimitExcept>
    </Directory>

    #DenyFiles
    #<Files ~ (\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)$>
    #    Order allow,deny
    #    Deny from all
    #</Files>
    
    # 限制浏览器类型
    # 手机使用CX文件管理时如果不配置DavClient就不能访问
    # 具体我也太明白这里如何配置
    BrowserMatch "^DavClient" redirect-carefully
    BrowserMatch "^RaiDrive" redirect-carefully
    
</VirtualHost>

 

3.1  将配置文件链接到sites-enabled目录

 

4. 配置ports.conf

添加  Listen 8090  到配置文件即可

 

5.重启apache2服务