Mà không muốn cài đặt phiền phức, thì docker là cách nhanh gọn lẹ.
Chia sẻ stack WordPress Docker ở đây để sau này tiện chạy lại. full-width
Tạo thư mục chứa dự án.
mkdir -p /home/wp-project
Tạo Docker Compose file YML
cd /home/wp-project && vi docker-compose.yml
docker-compose.yml
version: "3.9" services: wordpress: container_name: wordpress image: wordpress:php8.1-apache restart: always stdin_open: true tty: true environment: WORDPRESS_DB_HOST: mariadb WORDPRESS_DB_USER: db_user WORDPRESS_DB_PASSWORD: db_user_pass WORDPRESS_DB_NAME: db_name volumes: - wordpress_data:/var/www/html - ./wordpress:/var/www/html mariadb: container_name: mariadb image: mariadb restart: always environment: MYSQL_DATABASE: db_name MYSQL_USER: db_user MYSQL_PASSWORD: db_user_pass MYSQL_RANDOM_ROOT_PASSWORD: 'root_pass' volumes: - db_data:/var/lib/mysql nginx: container_name: nginx image: nginx:stable restart: unless-stopped ports: - 80:80 - 443:443 volumes: - ./nginx/conf:/etc/nginx/conf.d - ./certbot/conf:/etc/nginx/ssl - ./certbot/data:/var/www/html certbot: container_name: certbot image: certbot/certbot:latest command: certonly --webroot --webroot-path=/var/www/html --email [email protected] --agree-tos --no-eff-email -d domain.com -d www.domain.com volumes: - ./certbot/conf:/etc/letsencrypt - ./certbot/logs:/var/log/letsencrypt - ./certbot/data:/var/www/html volumes: db_data: wordpress_data:
Cập nhật giá trị các tham số: db_user, db_user_pass, db_name, root_pass thành giá trị thực tế bạn muốn cấu hình
Cấu hình Nginx
mkdir -p /home/wp-project/nginx/conf && vi /home/wp-project/nginx/conf/default.conf
/home/wp-project/nginx/conf/default.conf
server { listen [::]:80; listen 80; server_name domain.com www.domain.com; root /var/www/html; index index.php; location ~ /.well-known/acme-challenge { allow all; root /var/www/html; } location / { try_files $uri @apache; } location ~ ^/.user.ini { deny all; } location ~* .(svg|svgz)$ { types {} default_type image/svg+xml; } location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { allow all; log_not_found off; access_log off; } location @apache { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $host; proxy_pass http://wordpress:80; } location ~[^?]*/$ { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $host; proxy_pass http://wordpress:80; } location ~ .php$ { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $host; proxy_pass http://wordpress:80; } location ~/. { deny all; access_log off; log_not_found off; } }
Lưu ý: thay domain.com bằng tên Domain cần cài đặt
Triển khai WordPress với Docker Compose
cd /home/wp-project && docker-compose up -d
Update SSL: /home/wp-project/nginx/conf/default.conf
server { listen [::]:80; listen 80; server_name domain.com www.domain.com; return 301 https://domain.com$request_uri; } server { listen [::]:443 ssl; listen 443 ssl; http2 on; server_name www.domain.com; ssl_certificate /etc/nginx/ssl/live/domain.com/fullchain.pem; ssl_certificate_key /etc/nginx/ssl/live/domain.com/privkey.pem; return 301 https://domain.com$request_uri; } server { listen [::]:443 ssl; listen 443 ssl; http2 on; server_name domain.com; ssl_certificate /etc/nginx/ssl/live/domain.com/fullchain.pem; ssl_certificate_key /etc/nginx/ssl/live/domain.com/privkey.pem; root /var/www/html; index index.php; location ~ /.well-known/acme-challenge { allow all; root /var/www/html; } location / { try_files $uri @apache; } location ~ ^/.user.ini { deny all; } location ~* .(svg|svgz)$ { types {} default_type image/svg+xml; } location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { allow all; log_not_found off; access_log off; } location @apache { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $host; proxy_pass http://wordpress:80; } location ~[^?]*/$ { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $host; proxy_pass http://wordpress:80; } location ~ .php$ { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $host; proxy_pass http://wordpress:80; } location ~/. { deny all; access_log off; log_not_found off; } }
Lưu ý: thay domain.com bằng tên Domain cần cài đặt
Khởi động lại Nginx
cd /home/wp-project && docker-compose restart nginx
Sau đó truy cập https://domain.com để kiểm tra cấu hình!
1 số lệnh hữu ích khác
# Renew SSL
cd /home/wp-project && docker-compose run certbot renew
# Reload Nginx
cd /home/wp-project && docker-compose exec nginx nginx -s reload
Lệnh test requests cho website WordPress vừa cấu hình
wrk -t4 -c400 -d60s https://domain.com
Cách nhanh nhất để tiến hành kiểm thử performance thực tế với LEMP stack in Docker trên 1 con VPS
Trả lờiXóaĐăng nhận xét