WordPress博客Docker容器docker

以DockerCompose的形式搭建基于nginx与wordp

2018-04-09  本文已影响20人  褪色的记忆1994

因为习惯使用nginx,又需要配置https证书,使用原生的wordpress镜像需要转端口会出现各种问题,所以最后以DockerCompose的形式结合nginx与wordpress镜像完美解决了相关问题。

version: "2"
services:
 nginx:
   image: nginx:alpine
   restart: always
   volumes:
       - ./cert:/etc/nginx/cert
       - ./conf/nginx.conf:/etc/nginx/nginx.conf
       - /home/wordpress:/var/www/html
   ports:
     - "443:443"
   links:
       - wordpress
 wordpress:
   image: wordpress:4.9.4-php7.0-fpm
   ports:
     - 9000:9000
   volumes:
     - /home/wordpress:/var/www/html
   restart: always
   environment:
       - WORDPRESS_DB_NAME=wordpress
       - WORDPRESS_TABLE_PREFIX=wp_
       - WORDPRESS_DB_HOST=修改为数据库的IP地址
       - WORDPRESS_DB_PASSWORD=密码
       - WORDPRESS_DB_USER=用户
server {
        listen 443;
        server_name www.test.com;  #修改为自己的域名
        
        ssl on;
        root /var/www/html;
        index index.php index.html;
        ssl_certificate   cert/test.pem;   #修改为自己的证书地址
        ssl_certificate_key  cert/test.key;  #修改为自己的密钥地址
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;

        location / {
            try_files $uri $uri/ /index.php?$args;
        }
 
        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass wordpress:9000;   #wordpress地址
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
        }
    }

个人博客:https://blog.xvjialing.xyz

github主页:https://github.com/xvjialing

上一篇 下一篇

猜你喜欢

热点阅读