安装docker

debian 搭建过程(ubuntu系统类似)

更新一下包(必须)

sudo apt update -y 
apt-get update && apt-get install -y wget vim

安装docker

wget -qO- get.docker.com | bash
systemctl enable docker

安装docker-compose

sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

​ 为docker-compose增加x执行权限

sudo chmod +x /usr/local/bin/docker-compose

​ 执行后,查看version,检查是否成功

docker-compose --version

​ 防止docker日志无限打印塞满空间

cat > /etc/docker/daemon.json <<EOF`
`{`
    `"log-driver": "json-file",`
    `"log-opts": {`
        `"max-size": "20m",`
        `"max-file": "3"`
    `},`
    `"ipv6": true,`
    `"fixed-cidr-v6": "fd00:dead:beef:c0::/80",`
    `"experimental":true,`
    `"ip6tables":true`
`}`
`EOF

​ 建docker管理目录(方便管理docker数据,~目录可根据自己喜好修改)

mkdir -p  ~/docker_data

安装nginx(或Nginx Proxy Manager)

​ docker安装nginx代码如下:

docker run -d --name nginx -p 80:80 -p 443:443 -v /root/docker_data/nginx/nginx.conf:/etc/nginx/nginx.conf -v /root/docker_data/nginx/certs:/etc/nginx/certs -v /root/docker_data/nginx/html:/usr/share/nginx/html nginx:latest

ps:这里将虚拟机的nginx的nginx.conf、nginx/certs、nginx/html映射到了本机中,方便本机中维护配置、证书等

安装alist

​ alist不用多说了,可以挂载多个网盘,教程很多,不列举了

docker run -d --restart=always -v /root/docker_data/alist:/opt/alist/data -p 5244:5244 -e PUID=0 -e PGID=0 -e UMASK=022 --name="alist" xhofe/alist:main

​ 查看alist默认密码

docker exec -it alist ./alist admin

安装halo

​ halo是一款个人博客系统,对新手朋友较友好。 详见:https://halo-docs.vercel.app/

docker run -it -d --name halo -p 8090:8090 -v ~/docker_data/.halo:/root/.halo --restart=unless-stopped halohub/halo

配置nginx网关映射

修改域名、路径、端口转发,实现访问不同的应用,如我们上一步搭建的halo博客、alist网盘等应用。以下是一个nginx.conf的例子

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;


    keepalive_timeout 65;

    server {
		listen       80;
		listen  [::]:80;
        server_name 你的域名;

        location / {
			# proxy_pass配置你应用的ip:端口号,可以是本机,也可以是docker或是其他网路主机,如上一步halo博客8090
			proxy_pass http://yourIP:yourPort/;
			rewrite ^/(.*)$ /$1 break;
			proxy_redirect off;
			proxy_set_header Host $host;
			proxy_set_header X-Forwarded-Proto $scheme;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_set_header Upgrade-Insecure-Requests 1;
			proxy_set_header X-Forwarded-Proto https;
		}
    }
	
	server {
        listen 443 ssl;
		listen [::]:443 ssl;
        server_name 你的域名;
		
		ssl_certificate /etc/nginx/certs/cert.pem;
		ssl_certificate_key /etc/nginx/certs/key.pem;
		
		#if ($scheme != "https") {
			#return 301 https://$server_name$request_uri;
		#}
		
		location / {
			proxy_pass http://yourIP:yourPort/;

			rewrite ^/(.*)$ /$1 break;
			proxy_redirect off;
			proxy_set_header Host $host;
			proxy_set_header X-Forwarded-Proto $scheme;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_set_header Upgrade-Insecure-Requests 1;
			proxy_set_header X-Forwarded-Proto https;

		}
    }
}