apache2配置强制ssl连接的webdav
Feb 2, 2021
»
apache2
多网站对应单ssl证书
1、启用ssl功能模块
sudo a2enmod ssl
否则会报错:Invalid command ‘SSLEngine’, perhaps misspelled or defined by a module not included in the server configuration
参考链接:
apache2 ssl配置
2、创建配置文件
该配置文件应该放在/etc/apache2/sites-available/目录下
并在/etc/apache2/sites-enabled目录下创建软连接
# 该配置文件需要配合在http://ip或domain/建站时,仍旧存在一些问题
# DavLockDB /var/www/mywebdav/DavLock
<VirtualHost *:443>
ServerAdmin root@localhost
#ServerName kasumiksm.com
SSLEngine on # 开启ssl认证
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM
SSLHonorCipherOrder on
#指定证书相关文件路径
SSLCertificateFile /etc/ssl/kasumiksm.com.crt/Apache/2_kasumiksm.com.crt
SSLCertificateKeyFile /etc/ssl/kasumiksm.com.crt/Apache/3_kasumiksm.com.key
SSLCertificateChainFile /etc/ssl/kasumiksm.com.crt/Apache/1_root_bundle.crt
DocumentRoot /var/www/webdav
#Alias /webdav /var/www/webdav # 该语句只有配合
#DocumentRoot、Directory才有用
<Location /webdav>
DAV On # 开启webdav功能
Options Indexes MultiViews
AllowOverride None
Order allow,deny
allow from all
AuthType Basic
#登陆 WebDAV 使用的用户名,可修改
AuthName "pi"
AuthUserFile /etc/apache2/webdav.password
Require valid-user
</Location>
#ErrorLog /var/log/httpd/mywebdav_error.log
#CustomLog /var/log/httpd/mywebdav_access.log common
</VirtualHost>
#将80的请求转至443,可以不用
<VirtualHost *:80>
ServerAdmin root@localhost
ServerName kasumiksm.com
RewriteEngine on # 启用重写
#RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{REQUEST_URI} !^/webdav{/}?$
# 重写条件,%{REQUEST_URI}表示访问的相对地址,就是相对根目录的
# 地址,就是域名/后面的成分,格式上包括最前面的“/”
#RewriteRule ^(.)$ https://%{SERVER_NAME}$1 [L,R]
RewriteRule ^(.*)$ https://kasumiksm.com/webdav/
# 匹配所有字符串,并将其改写为后面的形式
</VirtualHost>
参考链接: .htaccess中的apache rewrite规则写法详解