為了能夠自由的同步 Zotero 中的論文,我們可以透過 WebDAV 來同步電腦中的論文到雲端上。以下分為四個步驟介紹如何在 Ubuntu 使用 NGINX 設定帶有 HTTPS、Auth 的 WebDAV 功能。
A. 安裝與設定 NGINX
- 安裝 nginx-full (dep: libnginx-mod-http-dav-ext)
$ apt install nginx-full
- 加入 WebDAV 設定檔
$ sudo nano /etc/nginx/sites-available/webdav.conf
$ cd /etc/nginx/sites-enabled
$ ln -s ../sites-available/webdav.conf .
- webdav.conf 內容
- 如果你要使用 domain name,請在 listen 前面補上 server_name
- server_name your-webdav-domain.com;
B. 測試 NGINX WebDAV (w/o HTTPS/Authentication)
- 確認設定檔正確
$ nginx -t
1 2 3 |
$ nginx –t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful |
- 重啟 NGINX
$ systemctl restart nginx
- 透過
cadaver
測試 WebDAV 是否有啟動成功$ apt install cadaver
$ cadaver http://your-webdav-domain.com
1 2 3 4 |
$ cadaver http://your-webdav-domain.com dav:/> ls Listing collection `/‘: succeeded. dav:/> |
C. 設定 NGINX Authentication
Reference: Restricting Access with HTTP Basic Authentication
- 產生 Basic Authentication 檔案 (把 user1 改成你想要的帳號名稱)
$ htpasswd -c /etc/nginx/.htpasswd user1
- 確認檔案產生成功
$ cat /etc/nginx/.htpasswd
1 2 3 4 |
$ cat /etc/nginx/.htpasswd user1:$apr1$/woC1jnP$KAh0SsVn5qeSMjTtn0E9Q0 user2:$apr1$QdR8fNLT$vbCEEzDj7LyqCMyNpSoBh/ user3:$apr1$Mr5A0e.U$0j39Hp5FfxRkneklXaMrr/ |
- 在 webdav.conf 中啟動 HTTP Basic Authentication
1 2 3 4 5 |
server { ... auth_basic “Restricted webdav”; auth_basic_user_file /etc/nginx/.htpasswd; } |
- 重啟 NGINX
$ systemctl restart nginx
- 透過
cadaver
測試 WebDAV 是否有啟動成功$ cadaver http://your-webdav-domain.com
1 2 3 4 5 6 7 |
$ cadaver http://your-webdav-domain.com Authentication required for Restricted webdav on server `your–webdav–domain.com‘: Username: user1 Password: dav:/> ls Listing collection `/’: succeeded. dav:/> |
D. 設定 WebDAV HTTPS
- 安裝 certbot
$ apt install certbot
- 設定 certbot
$ certbot --nginx your-webdav-domain.com
- 透過
cadaver
測試 WebDAV 是否有啟動成功 (https://your-webdav-domain.com)
1 2 3 4 5 6 7 |
$ cadaver https://your-webdav-domain.com Authentication required for Restricted webdav on server `your–webdav–domain.com‘: Username: user1 Password: dav:/> ls Listing collection `/’: succeeded. dav:/> |
Leave a Reply