typora/note/Blog/折腾wordpress.md
2024-12-12 10:48:55 +08:00

83 lines
2.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

### 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 样式恢复正常