### docker 部署 mysql

```bash
docker run -d --privileged=true \
--net=internal \
--name mysql \
-v /root/data/mysql:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=XXXXX \
-p 3206:3306 \
mysql:5.7
```

### docker 部署 wordpress

```bash
docker run -itd \
--name wp \
--net=internal \
--link mysql \
wordpress:latest
```



### Nginx 代理 wordpress

```nginx
server{
    listen 443 ssl;
    server_name test.heysq.com;
    ssl_certificate      /etc/nginx/ssls/heysq_com/cert.pem;
    ssl_certificate_key  /etc/nginx/ssls/heysq_com/key.pem;
    ssl_session_timeout 5m;
    client_max_body_size 500m;
    location / {
        proxy_pass http://wp:80;
        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;
    }
}
```

### 访问test.heysq.com

- 页面报错阻止加载混合活动内容，因为浏览器安全策略，禁止https网站内部加载http请求

  ![image-20231220101825710](https://blog-heysq-1255479807.cos.ap-beijing.myqcloud.com/note/image-20231220101825710.png)

### wordpress配置

- 在没有页面样式的情况下进行wordpress配置数据库和站点信息

- 配置完站点信息后，进入wordpress容器查看生成的`wp-config.php`文件

  <img src="https://blog-heysq-1255479807.cos.ap-beijing.myqcloud.com/note/image-20231220102119917.png" alt="image-20231220102119917" style="zoom:50%;" />

- 按照wordpress官网的教程，在`wp-config.php`文件中添加以下代码

```php
define('FORCE_SSL_ADMIN', true);

if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false){
    $_SERVER['HTTPS'] = 'on';
    $_SERVER['SERVER_PORT'] = 443;
}
if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
    $_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
}

define('WP_HOME','https://test.heysq.com/'); // 替换成自己网站的域名
define('WP_SITEURL','https://test.heysq.com/'); // 替换成自己网站的域名
```

- 刷新站点页面，wordpress 样式恢复正常

