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

2.2 KiB
Raw Blame History

docker 部署 mysql

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

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

Nginx 代理 wordpress

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

wordpress配置

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

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

    image-20231220102119917
  • 按照wordpress官网的教程wp-config.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 样式恢复正常