小书匠
apache2 设置 cross-origin resource sharing
现在的浏览器,有些 ajax 请求,会先执行 pre-flight
, 导致即使服务器配置了 Access-Control-Allow-Origin
, 依然会报跨域请求的错误.
这里记录下在 apache 里的解决方法.
打开 rewrite mod
conf/httpd.confapache 1行
- 1LoadModule rewrite_module modules/mod_rewrite.so
conf/conf-available/dav.confapache 10行
- 1# Always set these headers.
- 2Header always set Access-Control-Allow-Origin "*"
- 3Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
- 4Header always set Access-Control-Max-Age "1000"
- 5Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token"
- 6
- 7# Added a rewrite to respond with a 200 SUCCESS on every OPTIONS request.
- 8RewriteEngine On
- 9RewriteCond %{REQUEST_METHOD} OPTIONS
- 10RewriteRule ^(.*)$ $1
参考文章
即使按照上面的方法,还是会有 401 的错误, 最后版本.
添加 LimitExcept OPTIONS 信息
- 1<Directory "/var/lib/dav/data/">
- 2 Dav On
- 3 Options Indexes FollowSymLinks
- 4
- 5 # Always set these headers.
- 6
- 7 Header always set Access-Control-Allow-Origin "*"
- 8 Header always set Access-Control-Allow-Headers "*"
- 9 Header always set Access-Control-Expose-Headers "ETag"
- 10 Header always set Access-Control-Allow-Methods "*"
- 11 Header always set Access-Control-Allow-Credentials "true"
- 12 # Added a rewrite to respond with a 200 SUCCESS on every OPTIONS request.
- 13 RewriteEngine On
- 14 RewriteCond %{REQUEST_METHOD} OPTIONS
- 15 RewriteRule ^(.*)$ blank.html
- 16 AuthType Basic
- 17 AuthName "WebDAV"
- 18 AuthUserFile "/user.passwd"
- 19 <LimitExcept OPTIONS>
- 20 Require valid-user
- 21 </LimitExcept>
- 22</Directory>
- 23
docker 启动失败分析处理
由于直接在 docker 容器里修改了文件,导致 容器无法正常启动.(注:不建议直接在容器内修改文件)
- 1docker ps -a
- 2docker logs {容器id}
报错信息
- 1Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
重新修改配置文件 , 将 rewrite mods 打开
- 1docker cp {容器id}:/usr/local/apache2/conf/conf-available/dav.conf ./
- 2vi dav.conf
- 3docker cp ./dav.conf {容器id}:/usr/local/apache2/conf/conf-available/
webdav 协议不支持递归创建不存在的目录问题
- 1# 逆向递归创建目录
- 2ensureDir = (client, paths, cb)->
- 3 client.exists(paths.join("/")).then((isExists)->
- 4 if isExists
- 5 # 结束递归
- 6 cb()
- 7 else
- 8 if paths.length <= 1
- 9 # 创建最开始一层的目录,并结束递归
- 10 client.createDirectory(paths.join("/")).then(()->
- 11 cb()
- 12 ).catch((error)->
- 13 cb(error)
- 14 )
- 15 else
- 16 ensureDir(client, paths.slice(0, -1), (error)->
- 17 if error
- 18 cb(error)
- 19 else
- 20 client.createDirectory(paths.join("/")).then(()->
- 21 cb()
- 22 ).catch((error)->
- 23 cb(error)
- 24 )
- 25 )
- 26 )
快速制作 u 盘引导程序
https://github.com/ventoy/Ventoy
https://www.ventoy.net/en/index.html
生活
一声哈武镖车走,年年江湖平安回