WordPress管理画面と公開ドメインを別にする

優

どうも!WordPress屋さんの優です。

 

今回はWordPressのドメインを管理画面と公開側でドメインをわける設定のご紹介。

 

  • 管理用ドメイン:admin.example.local
    /var/www/vhosts/admin.example.local/
  • 公開用ドメイン:www.example.local
    /var/www/vhosts/www.example.local/

そんな風にわけていきます。

 

ドメインを管理と公開側でわけることによって何が嬉しいか

  • サーバをわけるのが簡単
    ※管理側と公開側サーバにてネットワーク同期する仕組みは必要です。
  • セキュリティがガガン!とあがります
    管理側にはIP制限もしやすく、プライベートIPで設定してVPN接続で更新しても良し。
  • 静的サイトに!
    いっそのこと公開側を静的サイトにしてしまってもよしこちゃんです。

 

そんなわけで進めていきましょ~。

 

インストールと設定

必要なものをインストールするよ!

# yum install httpd mariadb mariadb-server httpd-devel php php-mysql wget unzip rsync

 

 

DBとWEBサーバを起動させます。

# systemctl start mariadb
# systemctl enable mariadb

# systemctl start httpd
# systemctl enable httpd

 

ファイアウォールで80番ポートを開けましょう。

# firewall-cmd --permanent --zone public --add-service http
# firewall-cmd --reload

 

WordPress用のDBとユーザを作成します。

# mysql -u root

MariaDB [(none)]> CREATE DATABASE wpdb;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON wpdb.* TO "wpdbuser"@"localhost" IDENTIFIED BY 'wpdbpassword';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit
Bye

 

 

WordPressのダウンロードと管理用ドメインの設定を行います。

# mkdir -p /var/www/vhosts

# cd /var/www/vhosts
 
# wget https://ja.wordpress.org/wordpress-4.8.2-ja.zip
 
# unzip wordpress-4.8.2-ja.zip
 
# mv wordpress admin.example.local
 
# cp /var/www/vhosts/admin.example.local/wp-config-sample.php /var/www/vhosts/admin.example.local/wp-config.php

 

DBとの接続設定はこちら

# vi /var/www/vhosts/admin.example.local/wp-config.php


define('DB_NAME', 'wpdb');

/** MySQL データベースのユーザー名 */
define('DB_USER', 'wpdbuser');

/** MySQL データベースのパスワード */
define('DB_PASSWORD', 'wpdbpassword');

/** MySQL のホスト名 */
define('DB_HOST', 'localhost');

 

 

公開ドメイン用ディレクトリの作成

# mkdir -p /var/www/vhosts/www.example.local

 

wp-contentのコピー

# rsync -arv /var/www/vhosts/admin.example.local/wp-content/ /var/www/vhosts/www.example.local/wp-content/

 

公開用ドメインディレクトリにindex.phpを置きますよ!

# cp -arv /var/www/vhosts/admin.example.local/index.php /var/www/vhosts/www.example.local/index.php

 

公開用ドメインディレクトリのindex.phpに編集して管理用ドメインを参照するように設定します。

# vi /var/www/vhosts/www.example.local/index.php

<?php
/**
 * Front to the WordPress application. This file doesn't do anything, but loads
 * wp-blog-header.php which does and tells WordPress to load the theme.
 *
 * @package WordPress
 */

/**
 * Tells WordPress to load the WordPress theme and output it.
 *
 * @var bool
 */
define('WP_USE_THEMES', true);

/** Loads the WordPress Environment and Template */
//require( dirname( __FILE__ ) . '/wp-blog-header.php' );
require( '/var/www/vhosts/admin.example.local/wp-blog-header.php' );

 

画像用ディレクトリの作成

# mkdir -p /var/www/vhosts/www.example.local/images

 

権限の設定を行います

# chown apache:apache -R /var/www/vhosts

 

バーチャルホストの設定を行いましょう。

# vi /etc/httpd/conf.d/vhost.conf

NameVirtualHost *:80
 
<VirtualHost *:80>
    ServerName   admin.example.local
    DocumentRoot /var/www/vhosts/admin.example.local
 
    LogLevel  warn
    ErrorLog  logs/error_log
    CustomLog logs/access_log combined
 
    <Directory />
        Options FollowSymLinks
        AllowOverride All
    </Directory>
</VirtualHost>


<VirtualHost *:80>
    ServerName   www.example.local
    DocumentRoot /var/www/vhosts/www.example.local
 
    LogLevel  warn
    ErrorLog  logs/error_log
    CustomLog logs/access_log combined
 
    <Directory />
        Options FollowSymLinks
        AllowOverride All
    </Directory>
</VirtualHost>

 

反映します。

# systemctl restart httpd

 

 

hostsに設定

192.168.11.37 www.example.local admin.example.local

 

アクセスを行います。

http://admin.example.local/wp-admin/

 

 

今回は上記のように設定して、【WordPressをインストール】をクリックします。

 

 

 

 

ログインを行いましょう。

 

 

 

  • WordPressにアドレス(URL)に管理画面用ドメイン
  • サイトアドレス(URL)に公開用ドメインの

そんな風に設定してみてくださいね!

 

 

はい。

 

 

投稿を行いますよ。

 

 

 

さてさて、出来ましたね。

 

 

 

もちろん公開用ドメインからログインは出来ません。

 

画像ディレクトリの設定ですよ!

上記のように設定します。

 

 

 

画像をアップロードしましょう。

 

 

表示されましたね。

もっと設定したかったですか?ごめんなさい、これだけです。

 

お疲れ様です。

 

 

最新情報をチェックしよう!
>システム構築・保守に特化した会社です。

システム構築・保守に特化した会社です。

システムの構築・保守運用「システムガーディアン」 社内システム担当が欲しいが、専属で雇うほどの仕事量はない。 必要な時に必要なだけ頼りたいというお悩みを持つ企業様へ専門知識を持って対応を行っております。 サーバから各種システムまで自社・他社で構築されたシステムに対してサポートを行っております。

CTR IMG