├── .gitignore ├── Dockerfile ├── README.md ├── config └── nginx │ ├── default │ └── fastcgi_params ├── scripts └── install.sh └── web └── server.php /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | vendor 3 | composer* 4 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:jessie 2 | MAINTAINER oliver@xama.us 3 | 4 | # Default webdav user (CHANGE THIS!) 5 | ENV WEBDAV_USERNAME admin 6 | ENV WEBDAV_PASSWORD admin 7 | 8 | # Defaults 9 | WORKDIR /var/webdav 10 | VOLUME /var/webdav/public 11 | VOLUME /var/webdav/data 12 | 13 | # Install nginx with php5 support 14 | RUN apt-get update && \ 15 | DEBIAN_FRONTEND=noninteractive apt-get install -y nginx php5-fpm && \ 16 | rm -rf /var/lib/apt/lists/* 17 | 18 | # Install SabreDAV 19 | RUN php -r "readfile('http://getcomposer.org/installer');" > composer-setup.php && \ 20 | php composer-setup.php --install-dir=/usr/bin --filename=composer && \ 21 | php -r "unlink('composer-setup.php');" && \ 22 | composer require sabre/dav ~3.1.3 && \ 23 | rm /usr/bin/composer 24 | 25 | # Set up entrypoint 26 | COPY scripts/install.sh /install.sh 27 | 28 | # Configure nginx 29 | COPY config/nginx/default /etc/nginx/sites-enabled/default 30 | COPY config/nginx/fastcgi_params /etc/nginx/fastcgi_params 31 | 32 | # forward request and error logs to docker log collector 33 | RUN ln -sf /dev/stdout /var/log/nginx/access.log && \ 34 | ln -sf /dev/stderr /var/log/nginx/error.log 35 | 36 | # copy server.php for client -- sabredav communication 37 | COPY web/server.php /var/webdav/server.php 38 | 39 | CMD /install.sh && service php5-fpm start && nginx -g "daemon off;" 40 | 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # docker-nginx-webdav 2 | WebDAV (SabreDAV) Docker Image with authentication running on nginx. 3 | 4 | ## About 5 | 6 | This is probably the first one working WebDAV image for docker. 7 | It uses nginx as webserver and SabreDAV as WebDAV backend. This way this image is compatible with windows mounting. 8 | Also, it features a digest authentication. 9 | 10 | ## Getting started 11 | 12 | You can run this container the following way: 13 | 14 | ```` 15 | docker run -d \ 16 | -e WEBDAV_USERNAME=admin \ 17 | -e WEBDAV_PASSWORD=admin \ 18 | -p 8080:80 \ 19 | -v /path/to/your/files:/var/webdav/public \ 20 | xama/nginx-webdav 21 | ```` 22 | 23 | This will start a new webdav instance on `http://localhost:8080` with the given username and password for authentication. 24 | -------------------------------------------------------------------------------- /config/nginx/default: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80 default_server; 3 | server_name _; 4 | 5 | root /var/webdav; 6 | 7 | index index.html index.htm index.php; 8 | 9 | client_max_body_size 4g; 10 | 11 | rewrite (.*) /server.php$uri break; 12 | 13 | location / { 14 | # First attempt to serve request as file, then 15 | # as directory, then fall back to displaying a 404. 16 | try_files $uri $uri/ =404; 17 | } 18 | location ~ [^/]\.php(/|$) { 19 | fastcgi_split_path_info ^(.+?\.php)(/.*)$; 20 | fastcgi_pass unix:/var/run/php5-fpm.sock; 21 | fastcgi_index index.php; 22 | include fastcgi_params; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /config/nginx/fastcgi_params: -------------------------------------------------------------------------------- 1 | fastcgi_param QUERY_STRING $query_string; 2 | fastcgi_param REQUEST_METHOD $request_method; 3 | fastcgi_param CONTENT_TYPE $content_type; 4 | fastcgi_param CONTENT_LENGTH $content_length; 5 | 6 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 7 | fastcgi_param SCRIPT_NAME $fastcgi_script_name; 8 | fastcgi_param PATH_INFO $fastcgi_path_info; 9 | fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; 10 | fastcgi_param REQUEST_URI $request_uri; 11 | fastcgi_param DOCUMENT_URI $document_uri; 12 | fastcgi_param DOCUMENT_ROOT $document_root; 13 | fastcgi_param SERVER_PROTOCOL $server_protocol; 14 | 15 | fastcgi_param GATEWAY_INTERFACE CGI/1.1; 16 | fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; 17 | 18 | fastcgi_param REMOTE_ADDR $remote_addr; 19 | fastcgi_param REMOTE_PORT $remote_port; 20 | fastcgi_param SERVER_ADDR $server_addr; 21 | fastcgi_param SERVER_PORT $server_port; 22 | fastcgi_param SERVER_NAME $server_name; 23 | 24 | fastcgi_param HTTPS $https; 25 | 26 | # PHP only, required if PHP was built with --enable-force-cgi-redirect 27 | fastcgi_param REDIRECT_STATUS 200; 28 | 29 | fastcgi_param PHP_VALUE "upload_max_filesize=4G \n post_max_size=4G"; 30 | -------------------------------------------------------------------------------- /scripts/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## 4 | # Instructions to be executed on container start 5 | ## 6 | 7 | # Fix possible permission errors 8 | chown -R www-data:www-data /var/webdav 9 | chmod -R 777 /var/webdav 10 | 11 | # Create authentication file 12 | echo "$WEBDAV_USERNAME:SabreDAV:$(php -r "echo md5('$WEBDAV_USERNAME:SabreDAV:$WEBDAV_PASSWORD');")" >> .htdigest 13 | -------------------------------------------------------------------------------- /web/server.php: -------------------------------------------------------------------------------- 1 | setBaseUri('/'); 19 | 20 | /* Configure lock plugin */ 21 | $lockBackend = new DAV\Locks\Backend\File('data/locks'); 22 | $lockPlugin = new DAV\Locks\Plugin($lockBackend); 23 | $server->addPlugin($lockPlugin); 24 | 25 | /* Configure digest auth */ 26 | $authBackend = new Auth\Backend\File(__DIR__ . DIRECTORY_SEPARATOR . ".htdigest"); 27 | $authBackend->setRealm('SabreDAV'); 28 | $authPlugin = new Auth\Plugin($authBackend); 29 | 30 | /* Load plugins */ 31 | $server->addPlugin(new DAV\Browser\Plugin()); 32 | $server->addPlugin($authPlugin); 33 | 34 | /* Run the server */ 35 | $server->exec(); 36 | 37 | --------------------------------------------------------------------------------