nginx开启docker wordpress 全https

本来以为WordPress这么流行的开源框架加入docker 开启https是很简单的事。简单的是安装,https样式丢失,各种折腾。备份下,回头在看

mysql docker-compose 文件

version: '3.7'

services:
  mysql-dev:
    container_name: mysql-db
    image: mysql:5.7
    networks:
      - mysql_network
    environment:
      MYSQL_ROOT_PASSWORD: sys123
      MYSQL_DATABASE: wordpress
      MYSQL_USER: test
      MYSQL_PASSWORD: test
      MYSQL_ROOT_HOST: '%'
    ports:
      - '3306:3306'
    volumes:
      - "./conf:/etc/mysql/conf.d"
      - "./mysql/data:/var/lib/mysql"

    restart: always

networks:
  mysql_network:
    name: mysql_network

conf目录的my.cnf配置文件

# 添加如下配置后重启
[client]
default-character-set=utf8mb4

[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
skip-character-set-client-handshake=false

[mysql]
default-character-set=utf8mb4

wordpress docker-compose 文件

registry.cn-shanghai.aliyuncs.com/datayang/wordpress-5.3.2-php7.4-rpc:6.0镜像是把官方镜像加入grpc

version: '3.7'
services:
    java-rpc:
      image: registry.cn-shanghai.aliyuncs.com/datayang/wordpress-5.3.2-php7.4-rpc:6.0
      ports:
        - "8200:80"
      networks:
        - mysql_network
      environment:
        # 可以直接使用 上方 service 名 + 端口来获得链接
        WORDPRESS_DB_HOST: mysql-db:3306
        WORDPRESS_DB_USER: test
        WORDPRESS_DB_PASSWORD: test
      volumes:
        - "./wordpress:/var/www/html"
      restart: always
      #container内的root拥有真正的root权限
      privileged: true
networks:
  mysql_network:
    name: mysql_network
    external: true

nginx配置

wp.conf

server {
    listen 80;
    server_name test.test.com;
    return 301 https://$host$request_uri;
}
server {
    server_name test.test.com;
    listen 443 ssl;
    ssl on;
    ssl_certificate  /home/ssl/fullchain.cer;
    ssl_certificate_key /home/ssl/test.com.key;

    access_log /var/log/nginx/access.log main;
    # 主机中 WordPress 数据卷位置
    root  /home/wp_web/wordpress;


    location / {
        proxy_pass http://127.0.0.1:8333;
        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-Proto https;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires 7d;
        access_log off;
    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root html;
    }
}

注意!浏览器缓存,有几次设置正确了,但是浏览器保留之前的了,总是说我弄的不对 -0-

参考
地址

暂无评论
发表新评论