更新系统
apt update -y && apt upgrade -y && apt install -y curl wget sudo socat
安装docker
curl -fsSL https://get.docker.com | sh
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
创建目录
cd /home
mkdir web
cd web
mkdir html
mkdir mysql
mkdir certs
touch nginx.conf
nano docker-compose.yml
配置docker-compose
version: '3.8'
services:
nginx:
image: nginx
container_name: nginx
restart: always
ports:
- 80:80
- 443:443
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./certs:/etc/nginx/certs
- ./html:/var/www/html
depends_on:
- php
php:
image: php:fpm
container_name: php
restart: always
volumes:
- ./html:/var/www/html
depends_on:
- mysql
mysql:
image: mysql
container_name: mysql
restart: always
ports:
- 3306:3306
volumes:
- ./mysql:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=webroot
- MYSQL_DATABASE=web
- MYSQL_USER=asdasdasd
- MYSQL_PASSWORD=sdfdsfsaf
申请证书
curl https://get.acme.sh | sh
~/.acme.sh/acme.sh --register-account -m xxxx@gmail.com
~/.acme.sh/acme.sh --issue -d 你的vps域名 --standalone
下载证书
~/.acme.sh/acme.sh --installcert -d cn.0514.me --key-file /home/web/certs/key.pem --fullchain-file /home/web/certs/cert.pem
NGINX配置
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
client_max_body_size 1000m;
#上传限制参数1G以内文件可上传
# HTTP server
server {
listen 80;
server_name yuming.com;
# Redirect all HTTP requests to HTTPS
return 301 https://$host$request_uri;
}
# HTTPS server
server {
listen 443 ssl http2;
server_name yuming.com;
# http2 on;
ssl_certificate /etc/nginx/certs/cert.pem;
ssl_certificate_key /etc/nginx/certs/key.pem;
root /var/www/html;
index index.php;
# rewrite ^/vip.php(.*)$ /vip.php?s=$1 last;
try_files $uri $uri/ =404;
# PHP-FPM configuration
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
下载源码
maccms10 (苹果的cms,可不安装)
cd /home/web && wget https://github.com/magicblack/maccms_down/raw/master/maccms10.zip && sudo apt-get install -y unzip && unzip maccms10.zip -d html && rm maccms10.zip && mv /home/web/html/maccms10-master/* /home/web/html/
wordpress
cd /home/web && wget https://cn.wordpress.org/wordpress-6.2-zh_CN.zip && sudo apt-get install -y unzip && unzip wordpress-6.2-zh_CN.zip -d html && rm wordpress-6.2-zh_CN.zip && mv /home/web/html/wordpress/* /home/web/html/
运行
cd /home/web && docker-compose up -d
赋予权限
docker exec -it nginx chmod -R 777 /var/www/html docker exec -it php chmod -R 777 /var/www/html chown -R www-data:www-data /home/web/html chmod -R 755 /home/web/html chmod -R 775 /home/web/html/wp-content
安装PHP扩展
docker exec php apt update && docker exec php apt install -y libmariadb-dev-compat libmariadb-dev libzip-dev
docker exec php docker-php-ext-install mysqli pdo_mysql zip
重启php
docker restart php