MOMO

首页 > docker > 使用php-fpm + nginx + mariadb镜像部署wordpress

使用php-fpm + nginx + mariadb镜像部署wordpress

Jun 2018 06

生命不息,折腾不止

原料

  • docker-ce
  • docker-compose

架构

文件结构

touch docker-compose.yml 
mkdir -p conf / 
mkdir -p db-data / 
mkdir -p logs / nginx / 
mkdir -p wordpress /
mkdir -p cert /
  • docker-compose.yml:docker -compose配置文件
  • conf /:存放nginx配置,如虚拟主机等。
  • db-data /:mysql数据的目录
  • logs /:应用程序日志目录,nginx,mariadb和php-fpm。
  • wordpress /:所有wordpress文件
  • cert /: 网站证书、私钥

配置

docker-compose.yml

version: '2'

services:

        nginx:
                image: nginx
                ports:
                        - '80:80'
                        - '443:443'
                volumes:
                        - ./conf:/etc/nginx/conf.d
                        - ./cert:/usr/local/nginx/conf
                        - ./logs/nginx:/var/log/nginx
                        - ./wordpress:/var/www/html
                links:
                        - wordpress
                restart: always
        mariadb:
                image: mariadb
                volumes:
                        - ./db-data:/var/lib/mysql
                environment:
                        - MYSQL_ROOT_PASSWORD=xxx
                restart: always
        wordpress:
                image: wordpress:4.9.6-php7.2-fpm
                volumes:
                        - ./wordpress:/var/www/html
                environment:
                        - WORDPRESS_DB_HOST=mariadb
                        - WORDPRESS_DB_PASSWORD=xxx
                links:
                        - mariadb
                restart: always

nginx.conf

根据你的需求配置,这里列出最基本的

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        server_name _;

        return 301 https://$host;
}

server {
        listen [::]:443 ssl http2;
        listen 443 ssl http2;

        ssl on;

        ssl_certificate /usr/local/nginx/conf/example.com.crt;
        ssl_certificate_key /usr/local/nginx/conf/example.com.key;

        server_name example.com;

        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

        root /var/www/html;
        index index.php;

        access_log off;
        error_log /var/log/nginx/example-error.log;

        charset utf-8;

        location / {
                try_files $uri $uri/ /index.php?$args;
        }

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

运行

docker-compose up -d

备份

以后备份和迁移直接拷贝wordpress/ 和db-data/ 两个目录就可以了

--转载请注明: https://momo.cool/%e4%bd%bf%e7%94%a8php-fpm%e9%95%9c%e5%83%8f%e9%83%a8%e7%bd%b2wordpress/

1
说点什么

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
清靈語 Recent comment authors
  Subscribe  
提醒
清靈語
游客
清靈語

你好,我注意到网站域名数字证书已经过期 5 个月了,还请排查一下是否出现了什么问题。