1.docker 配置 pure-ftp
(1)安裝docker和docker-compose
sudo apt-get install docker.io sudo apt-get install docker-compose
(2) 創建文件路徑
mkdir /home/ftpfile
(3) 進入任意工作目錄
mkdir pure-ftp cd pure-ftp
(4)配置pure-ftpd(具體配置可根據需要更改, 可參考 https://blog.csdn.net/shanzhongyinzhe/article/details/49639703 )
vim pure-ftpd.conf
(5)編輯docker-compose文件
vim docker-compose.yml
ftp: image: "stilliard/pure-ftpd" ports: - "21:21" - "30000:30000" - "30001:30001" - "30002:30002" - "30003:30003" - "30004:30004" - "30005:30005" - "30006:30006" - "30007:30007" - "30008:30008" - "30009:30009" volumes: - "/home/ftpfile:/home/ftpfile" - "./pure-ftpd:/etc/pure-ftpd" environment: PUBLICHOST: "localhost"
(6) docker-compose up -d
(7) 進入ftp容器內
docker exec -it pureftp_ftp_1 /bin/bash
(8)創建用戶
useradd deity -g deity -d /home/ftpfile -s /sbin/nologin
(9)創建ftp虛擬用戶
pure-pw useradd user1 -u deity -g ftpgroup -d /home/ftpfile
pure-pw mkdb
(9) 重啟pure-ftp
service pure-ftpd restart
2.docker 配置 nginx
(1) 進入任意工作目錄
mkdir nginx cd nginx
(2) vim nginx.conf
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; 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; }
nginx.conf可以去nginx官網下載,然后在末尾花括號前加上 include /etc/nginx/conf.d/*.conf; 即可。
(3) 編寫子配置文件
mkdir nginx.conf.d cd nginx.conf.d
(4) vim image.vvshow.com.conf
server { listen 80; autoindex off; server_name image.vvshow.com; access_log /var/log/nginx/access.log combined; index index.html index.htm index.jsp; if ( $query_string ~* ".*[\;'\<\>].*" ) { return 404; } location / { root /home/ftpfile; add_header Access-Control-Allow-Origin *; } }
(5) cd .. vim docker-compose.yml
nginx: image: "hub.c.163.com/library/nginx" ports: - "80:80" volumes: - "/home/ftpfile:/home/ftpfile" - "./nginx.conf:/etc/nginx/nginx.conf" - "./nginx.conf.d:/etc/nginx/conf.d" environment: PUBLICHOST: "localhost"
(6) docker-compose up -d
(7) 修改/etc/hosts,可將本機ip 映射域名為 image.vvshow.com
(8) 此時瀏覽器訪問image.vvshow.com 映射的為 /home/ftpfile目錄
注:pure-ftp 和 nginx 的docker-compose.xml 內容可以合在一起