docker compose 安装部署 wordpress
1.docker compose
文件直接部署
按照官方部署教程可能会出现以下报错
No 'wp-config.php' found in /var/www/html, but 'WORDPRESS_...' variables supplied; copying 'wp-config-docker.php' (WORDPRESS_DB_HOST WORDPRESS_DB_NAME WORDPRESS_DB_PASSWORD WORDPRESS_DB_USER)
docker-compose.yml
换成如下模板即可解决
version: '3.1'
services:
wordpress:
image: wordpress:latest
restart: always
ports:
- 8080:80
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
- wordpress:/var/www/html
db:
image: mysql:8.0
restart: always
environment:
- "MYSQL_DATABASE=wordpress"
- "MYSQL_USER=wordpress"
- "MYSQL_PASSWORD=wordpress"
- "MYSQL_ROOT_PASSWORD=wordpress"
volumes:
- db:/var/lib/mysql
volumes:
wordpress:
db:
2.设置Nginx反代wordpress
server {
listen 80;
server_name your_domain.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
http2 on;
server_name your_domain.com;
# 证书的公私钥
ssl_certificate /root/.acme.sh/your_domain.com_ecc/fullchain.cer;
ssl_certificate_key /root/.acme.sh/your_domain.com_ecc/your_domain.com.key;
# gzip config
gzip on;
gzip_min_length 1k;
gzip_comp_level 9;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
gzip_vary on;
gzip_disable "MSIE [1-6]\.";
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
3.到网站中设置访问域名
用IP
登录到你的wordpress
后台,比如 1.2.3.4:8080
,到设置里去填写域名,如下图,即可以域名打开网站了
License:
CC BY 4.0