Sign inSign up

raysonlu/nginx-dav

By raysonlu

•Updated over 4 years ago

基于nginx官方镜像以及官方方法构建,带有dav-ext模块

Image
0

72

raysonlu/nginx-dav repository overview

⁠这是啥?

根据Nginx官方的“基于官方镜像添加第三方模块”⁠ 方法,添加了 nginx-dav-ext-module 和 headers-more-nginx-module 这两个模块的nginx镜像。 相关版本说明下面有提及,特别说明的是,在构建镜像中已添加了加载镜像配置到nginx.conf。

⁠What is it ?

A Nginx image for webdav, witch has nginx-dav-ext-module and headers-more-nginx-module .It build from official nginx image throught the official method -- Adding third-party modules to nginx official image⁠
Other Description:

  • Base Image : nginx:mainline-alpine
  • Nginx Version : Nginx 1.23.0
  • Module:
    • nginx-dav-ext-module ---- v3.0.0 ---- github⁠
    • https://github.com/openresty/headers-more-nginx-module ---- v0.34 ---- github⁠
  • Special Note : For out-of-the-box,the image has add the load_module config for these two module in nginx.conf when building.

⁠咋用? (How to use ? )

和Nginx官方镜像一样的使用方法。下面举例一些使用方法。

Just use it like the official Nginx image⁠ . Here list some examples.

⁠一般使用 (Normal Use)

⁠Run comman
docker run -d --name nginx-dav -p 80:80 \
-v {your conf.d directory}:/etc/nginx/conf.d \
-v {your wwwroot directory}:/usr/share/nginx/html \
raysonlu/nginx-dav:latest
⁠docker-compose.yml
version: "3"
services:
  nginx-dav:
    image: raysonlu/nginx-dav:latest
    container_name: nginx-dav
    ports:
        - 80:80
    volumes:
        - {your conf.d directory}:/etc/nginx/conf.d
        - {your wwwroot directory}:/usr/share/nginx/html

常用的挂载 (Some Command Mount)

  • /etc/nginx/conf.d 站点配置目录 (The website config directory)
  • /usr/share/nginx/html 网站根目录放置 (The website root directory)
  • /var/log/nginx Nginx默认的日志目录 (The default Nginx log directory)
  • /etc/nginx/nginx.conf Nginx的主配置文件,建议获取镜像中的nginx.conf后再用来挂载。(The Nginx main config file.If you want to mount this ,advise you get nginx.conf file from image and then to mount it.)

⁠使用非root用户运行Nginx (Running Nginx as a non-root user)

当你希望通过webdav管理的文件或目录不是root用户归属时,就需要考虑此运行模式。 首先,Docker执行挂载的文件或者目录时,它们的用户或用户组属性也会传递到容器里。其次,Docker容器启动时,是可以指定容器运行的用户,即使创建容器不能同时在容器里创建一个新用户,但可以使用系统里的某个uid 或 gid。 例如,系统有一个用户ngdav和一个用户组ngdav,uid:gid是1001:1001,那么,我们可以在系统上创建一个ngdav用户的目录/wedav,在创建容器时挂载到/usr/share/nginx/html/webdav,最后在容器启动命令中设置运行用户是1001:1001。 注意,运行此模式必须在启动容器前,对Nginx的主配置文件的内容进行一些修改,因此需要额外挂载。可以参考附录的非root运行的Nginx的nginx.conf。

You can consider this mode,when you want to the file or directory in your webdav service is not for root user. First,when you mount the file or directory, the user and usergroup attributes will be passed into the container. And then,we can specify the running user and usergroup at container start.Even if you cannot create a new user in container,you can use a uid or gid which in your system to set it. For example,there is a user ngdav and a usergroup ngdav in your system, the uid:gid id 1001:1001.We can create an directory /webdav for user ngdav, so that we mount it on the /usr/share/nginx/html/webdav, of course, we should set the runing user 1001:1001 in docker runing command. Note: To use this mode by Nginx image, we must edit the Nginx main config file content before the container start, so we must mount the nginx main config file. You can follow The nginx.conf for running nginx as a non-root user in the Appendix

⁠Run command
docker run -d --name nginx-dav -p 80:80 \
--user {uid}:{gid} \
-v {your nginx.conf}:/etc/nginx/nginx.conf \
-v {your conf.d directory}:/etc/nginx/conf.d \
-v {your website directory}:/usr/share/nginx/html\website \
raysonlu/nginx-dav:latest
⁠docker-compose.yml
version: "3"
services:
  nginx-dav:
    image: raysonlu/nginx-dav:latest
    container_name: nginx-dav
    ports:
        - 80:80
    volumes:
        - {your nginx.conf}:/etc/nginx/nginx.conf
        - {your conf.d directory}:/etc/nginx/conf.d
        - {your website directory}:/usr/share/nginx/html\website
    user: {uid}:{gid}

⁠使用htpasswd工具配置Nginx的Basic_Auth登录认证 (Config Basic_Auth of Nginx by htpasswd)

⁠安装htpasswd工具 (Install the htpasswd tool)

用你系统的包管理软件,搜索安装htpasswd,如果找不到,可以尝试apache2-utils。

To search and install the htpasswd by you package management tools in your system such as yum,apt, or try to search apache2-utils.

⁠创建用户密码认证文件 (Create the identity file)

htpasswd -c {your auth file path} {your username}

#然后输入两次密码 (will input password twice)

⁠在网站配置文件配置 (Use it in website config)

在网站配置文件中,设置auth_basic_user_file的值为认证文件的完整路径。可以参考附录中的“例子:webdav网站配置文件”

In your website config in your Nginx, set the identify file as value for auth_basic_user_file. You can follow the Example: config for a webdav website in the Appendix.

⁠附录 (Appendix)

⁠非root运行的Nginx的nginx.conf (The nginx.conf for running nginx as a non-root user)

#本镜像添加的模块
load_module modules/ngx_http_headers_more_filter_module.so;
load_module modules/ngx_http_dav_ext_module.so;

#非root用户运行nginx无需配置user项
#user root;

worker_processes  auto;

error_log  /var/log/nginx/error.log notice;

#需要重新配置pid文件位置
pid        /tmp/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    #需要重新配置这些文件路径
    client_body_temp_path /tmp/client_temp;
    proxy_temp_path       /tmp/proxy_temp_path;
    fastcgi_temp_path     /tmp/fastcgi_temp;
    uwsgi_temp_path       /tmp/uwsgi_temp;
    scgi_temp_path        /tmp/scgi_temp;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

⁠例子:webdav网站配置文件 (Example: config for a webdav website)

server {
    listen 443 ssl http2;
    server_name dav.mywebdav.com;
    client_max_body_size 50m;

    ssl_certificate /etc/nginx/conf.d/ssl/dav.mywebdav.com/cert.pem;
    ssl_certificate_key /etc/nginx/conf.d/ssl/dav.mywebdav.com/privkey.pem;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers on;

    gzip  on;
    gzip_min_length 1k;
    gzip_comp_level 5;
    gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css;
    gzip_disable "MSIE [1-6]\.";
    gzip_vary on;

    root /usr/share/nginx/html/dav;
    index index.html index.htm;

    location / {
        set $dest $http_destination;
       
        if (-d $request_filename) {
            rewrite ^(.*[^/])$ $1/;
            set $dest $dest/;
        }
       
        if ($request_method ~ (MOVE|COPY)) {
            more_set_input_headers 'Destination: $dest';
        }
        if ($request_method ~ MKCOL) {
            rewrite ^(.*[^/])$ $1/ break;
        }
       
        client_body_temp_path /tmp;
       
        dav_methods PUT DELETE MKCOL COPY MOVE;
       
        dav_ext_methods PROPFIND OPTIONS LOCK UNLOCK;
       
        create_full_put_path on;
        
        dav_access group:rw all:r;
       
        auth_basic "Welcome,pleas login";
        auth_basic_user_file /etc/nginx/conf.d/ssl/dav;
    }
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
}

Tag summary

Content type

Image

Digest

Size

10 MB

Last updated

over 4 years ago

docker pull raysonlu/nginx-dav