美文网首页
2020-07-02 配置nginx开启支持webdav允许ht

2020-07-02 配置nginx开启支持webdav允许ht

作者: 五大RobertWu伍洋 | 来源:发表于2020-07-02 15:00 被阅读0次

    我这边有一台之前的服务器 上nginx 开的文件上传接口

    1304 $ nginx -V
    nginx version: nginx/1.4.6 (Ubuntu)
    built by gcc 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
    TLS SNI support enabled
    configure arguments: --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_spdy_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module
    

    对应的nginx服务的配置文件内容, 启用nginx http上传和下载文件

            server {
            listen 80;
    
            root /home/share/;
            index banner.html banner.htm index.html index.htm;
    
            server_name upload.flyfuture.com;
    
            add_header Access-Control-Allow-Origin *;
            add_header Access-Control-Allow-Credentials true;
            add_header Access-Control-Allow-Headers X-Requested-With;
            add_header Access-Control-Allow-Methods PUT,POST,GET,DELETE,MOVE,COPY,MKCOL,OPTIONS;
            add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
    
            location /file {
            alias /home/share/;
            index file.htm;
            }
    
            location / {
    #
            if ($request_method = 'OPTIONS') {
            add_header Access-Control-Allow-Origin *;
            add_header Access-Control-Allow-Headers X-Requested-With;
            add_header Access-Control-Allow-Credentials true;
            add_header Access-Control-Allow-Methods 'PUT, DELETE, GET, POST, OPTIONS';
            add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
            return 204;
            }
    
            client_body_temp_path /home/share/upload/tmp;
            dav_methods PUT DELETE MKCOL COPY MOVE;
            #dav_ext_methods PROPFIND OPTIONS;
            create_full_put_path on;
            dav_access group:rw  all:r;
            root /home/share/upload;
    #       proxy_pass http://upload.flyfuture.com;
            error_page 405 =200 http://$host$request_uri;
            }
    
            location /upload {
            alias /home/share/upload;
            index file.htm;
            }
    }
    

    容器的话,文件上传的nginx 和读取的nginx 挂载同一个pv

    或者用同一个nginx也是OK的。 上面的配置中,最后的

    location /upload {
            alias /home/share/upload;
            index file.htm;
            }  
    

    就是 允许 /upload接口直接查看到文件列表了, 并且可以下载

    咱们可以考虑nginx上默认放开验证。真正使用时,有必要时可以在管理平台加授权,或者直接走nginx,不走管理平台的话,再考虑nginx的授权管理也行。

    https://blog.csdn.net/caofengtao1314/article/details/52837948

    这个是比较全的参考

    我们用的是第四种 nginx 开启支持webdav , --with-http_dav_module 选项为true

    相关文章

      网友评论

          本文标题:2020-07-02 配置nginx开启支持webdav允许ht

          本文链接:https://www.haomeiwen.com/subject/jhlrqktx.html