安装docker
# 安装所需依赖
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# 添加Docker仓库
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# 安装Docker CE
sudo yum install docker-ce docker-ce-cli containerd.io
# 启动Docker服务
sudo systemctl start docker
安装 docker-compose
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
docker-compose --version
配置docker-compose.yml
在当前目录下创建一个docker-compose.yml文件,对应./wordpress的路径:
image 指定了使用 wordpress:latest 镜像
ports 把容器的 80 端口映射到主机的 8000 端口
restart 设置为 always,表示始终重新启动容器
volumes(卷) 将主机中当前目录下的 ./wordpress 目录挂载到容器的 /home/wordpress/wordpress,用于持久化保存 WordPress 数据,果通过volumes挂载后,你在宿主机上修改了配置文件,容器内部也会自动同步改动,无需任何其他操作。
environment 设置了 WordPress 连接外部数据库的配置,包括数据库地址、用户名和密码
services:
wordpress:
image: wordpress:latest
ports:
- "8000:80"
restart: always
// 服务器项目路径:
volumes:
- ./wordpress:/home/wordpress/wordpress
environment:
- WORDPRESS_DB_HOST=X.X.X.X:3306
- WORDPRESS_DB_USER=数据库用户名
- WORDPRESS_DB_PASSWORD=数据库密码
启动docker-compose脚本
docker-compose up -d
配置nginx
映射到8000端口,对应上面的配置:proxy_pass http://127.0.0.1:8000;
重启nginx
server {
listen 80;
server_name bugu.25youpin.com;
#return 301 https://h5test.25youpin.com$request_uri;
rewrite ^(.*)$ https://$host$1 permanent;
}
server {
listen 443;
server_name bugu.25youpin.com;
ssl on;
ssl_certificate cert/2116658__25youpin.com.pem;
ssl_certificate_key cert/2116658__25youpin.com.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_redirect off;
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-Host $server_name;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400;
}
error_log /var/log/nginx/bugutest.log;
}
更改wordpress 配置文件
根目录下的wp-config.php文件:
<?php
/**
* The base configuration for WordPress
*
* The wp-config.php creation script uses this file during the installation.
* You don't have to use the web site, you can copy this file to "wp-config.php"
* and fill in the values.
*
* This file contains the following configurations:
*
* * Database settings
* * Secret keys
* * Database table prefix
* * ABSPATH
*
* @link https://wordpress.org/documentation/article/editing-wp-config-php/
*
* @package WordPress
*/
// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress' );
/** Database username */
define( 'DB_USER', 'hzbctest' );
/** Database password */
define( 'DB_PASSWORD', 'test@hzbc2019' );
/** Database hostname */
define( 'DB_HOST', '121.40.234.122:3306' );
/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8mb4' );
/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
/**#@+
* Authentication unique keys and salts.
*
* Change these to different unique phrases! You can generate these using
* the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}.
*
* You can change these at any point in time to invalidate all existing cookies.
* This will force all users to have to log in again.
*
* @since 2.6.0
*/
define( 'AUTH_KEY', 'put your unique phrase here' );
define( 'SECURE_AUTH_KEY', 'put your unique phrase here' );
define( 'LOGGED_IN_KEY', 'put your unique phrase here' );
define( 'NONCE_KEY', 'put your unique phrase here' );
define( 'AUTH_SALT', 'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT', 'put your unique phrase here' );
define( 'NONCE_SALT', 'put your unique phrase here' );
/**#@-*/
/**
* WordPress database table prefix.
*
* You can have multiple installations in one database if you give each
* a unique prefix. Only numbers, letters, and underscores please!
*/
$table_prefix = 'wp_';
/**
* For developers: WordPress debugging mode.
*
* Change this to true to enable the display of notices during development.
* It is strongly recommended that plugin and theme developers use WP_DEBUG
* in their development environments.
*
* For information on other constants that can be used for debugging,
* visit the documentation.
*
* @link https://wordpress.org/documentation/article/debugging-in-wordpress/
*/
define( 'WP_DEBUG', false );
/* 解决FTP上传问题,安装插件用*/
define("FS_METHOD","direct");
define("FS_CHMOD_DIR", 0777);
define("FS_CHMOD_FILE", 0777);
/* Add any custom values between this line and the "stop editing" line. */
/* That's all, stop editing! Happy publishing. */
/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
define( 'ABSPATH', __DIR__ . '/' );
}
/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';