docker里运行wordpress并添加https支持

使用Linux 六年多了,原以为安装下wordpress分分钟的事,但实际一波三折。还是对php-fmp不了解啊。想法非常简单,拉取wordpress的docker镜像并运行,当然默认是没有https支持的,我呢,让nginx反向代理到wordpress即可,然后给nginx加https,等于用户的数据到nginx这个过程是https的,之后nginx转发到本地的wordpress端口(http)。但是却一度陷入css丢失的状态。

至于wordpress如何安装,可以参考:https://docs.docker.com/compose/wordpress/

不过我改了数据库,我用了自己优化后的 mariadb,下面主要说https,https对于个人用户而言,letsencrypt是不错的选择,甚至唯一的选择了。下面的命令用于生成泛域名证书:

./certbot-auto certonly -d *.ssyer.com --manual --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory

最后,附上我的nginx配置文件:

server {
    listen 80;
    server_name www.kpromise.top kpromise.top;
    server_tokens off;
    return 301 https://$server_name$request_uri;
}
   
server {
    listen 443 ssl;
    server_name kpromise.top;
    charset uft-8;
    return 301 https://www.$host$request_uri;
    ssl_certificate /etc/letsencrypt/live/kpromise.top/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/kpromise.top/privkey.pem;
}
  
server {
    listen 443 ssl;
    server_name www.kpromise.top;
    server_tokens off;
    index index.php index.html index.htm;
    ssl_certificate /etc/letsencrypt/live/kpromise.top/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/kpromise.top/privkey.pem;
    ssl_ciphers \'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256\';
    ssl_prefer_server_ciphers on;
   
    location / {
        try_files $uri @apache;
    }
 
    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://localhost:8000;
    }
  
    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://localhost:8000;
    }
   
    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://localhost:8000;
    }
  
    location ~/\\. {
        deny all;
        access_log off;
        log_not_found off;
    }
}

一开始nginx配置非常简单,结果css总是加载不上来。试遍了网上的方法…

本博客若无特殊说明则由 full-stack-trip 原创发布
转载请点名出处:全栈之旅 > docker里运行wordpress并添加https支持
本文地址:https://www.kpromise.top/wordpress-inside-docker-container-behind-nginx-proxy-with-ssl/

发表评论

电子邮件地址不会被公开。 必填项已用*标注