2
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

docker、nginx-proxy、letsencrypt環境でwordpressするまで

Posted at

docker、nginx-proxy、letsencryptでとりあえずredmineするまでの環境でwordpressしたい

laravelしたい場合はこっち
docker、nginx-proxy、letsencrypt環境でlaravelするまで

├── wp(new)
│   ├──docker-compose.yml
│   ├──php
|   |  └──Dockerfile
│   └──nginx
|      └──default.conf
├── laravel
│   ├──docker-compose.yml
│   ├──php
|   |  └──Dockerfile
│   └──nginx
|      └──default.conf
├── redmine
│   └── docker-compose.yml
└── shared
    └── docker-compose.yml
wp/docker-compose.yml
version: '2'
services:
  nginx:
    image: nginx
    external_links:
      - mysql
    container_name: "wordpress-nginx"
    volumes:
      - ./src:/src
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
    environment:
      VIRTUAL_HOST: 〇〇.com
      LETSENCRYPT_HOST: 〇〇.com
      LETSENCRYPT_EMAIL: 〇〇@〇〇.com
    restart: always
  php:
    build: ./php
    container_name: "wordpress-php"
    volumes:
      - ./src:/src
      - ./php/php.ini:/usr/local/etc/php/php.ini
    restart: always

networks:
  default:
    external:
      name: shared
php/Dockerfile.
FROM php:7-fpm
RUN apt-get update \
		&& docker-php-ext-install pdo_mysql mysqli \
		&& mkdir -p /src

COPY php.ini /usr/local/etc/php/

WORKDIR /src
nginx/default.conf
server {
	listen 80;
	server_name localhost;
	root /src/;
	index index.php index.html index.htm;

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

	location ~ \.php$ {
		try_files $uri = 404;
		fastcgi_split_path_info ^(.+\.php)(/.+)$;
		fastcgi_pass wordpress-php:9000;
		fastcgi_index index.php;
		fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
		fastcgi_param PATH_INFO $fastcgi_path_info;
		include       fastcgi_params;
	}
}
cd wp
docker-compose up -d
wget https://ja.wordpress.org/latest-ja.tar.gz    
tar xzfv latest-ja.tar.gz > /dev/null
mv wordpress src

このままだとMixed Content警告が出てCSSが当たらない

cp src/wp-config-sample.php src/wp-config.php

データベースの設定、

src/wp-config.php

define('DB_NAME', 'wordpress');
define('DB_USER', 'root');
define('DB_PASSWORD', 'root');
define('DB_HOST', 'mysql');

// 省略

if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])
  && $_SERVER['HTTP_X_FORWARDED_PROTO'] === "https") {
  $_SERVER['HTTPS'] = 'on';
}
define('FORCE_SSL_LOGIN', true);
define('FORCE_SSL_ADMIN', true);

// wp-settings.phpを読み込む前に書かないとこのページにアクセスする権限がありません。となるので注意

/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');

参考

WordPress + HTTPS + リバースプロキシ = このページにアクセスする権限がありません。
Docker上でWordPressとnginx-proxyを連携(SSL対応)
DockerコンテナにWordPressをインストール

2
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?