如何在樱花VPS上运营多个WordPress博客(虚拟主机和Let’s Encrypt设置)
撰写本篇文章的背景。さくらのVPSでWordPressブログを1つ運営していたが、同じサーバーでもう1つ別のWordPressブログを立ち上げたいと思ったため。
将来,如果需要再次启动博客,我将把这篇文章留作备忘录。
的污染問題被廣泛關注,人們越來越重視保護地球。从设置Sakura VPS到第一个WordPress安装的步骤,请参考下面的文章。
即使是猫也能理解!Sakura VPS教程〜第一课:什么是VPS?〜
サーバーさくらのVPS独自ドメイン1example.com独自ドメイン2example.netWebサーバーApache2.4.6OSCentOS7データベースMySQLSSLLet’s Encrypt1つ目のWordPressブログを、example.comという独自ドメインで運営している状態で、2つ目のWordPressブログを独自ドメインexample.netで追加する場合の手順になります。
使用的是独立域名,使用的是”お名前ドットコム”。
从Sakura VPS契约到安装WordPress的步骤さくらのVPSを契約してから、サーバーの初期設定、WordPressインストールまでの流れは下記のとおりです。
今回は、すでにWordPressを1つインストールしている状態なので、手順8以降を設定していきます。
1.さくらのVPS契約
2.標準OSのインストール(CentOS7)
3.Apache(もしくはnginx)をインストール
4.PHPインストール
5.MySQL(もしくはMariaDB)をインストール
6.phpMyAdminをインストール(※必須ではない)
7.ファイアウォールの設定(※自動で有効になる)
//ここから追加設定
8.独自ドメインの取得(example.net)
9.ネームサーバーの設定
10.Apacheのバーチャルホスト設定
11.Let’s Encryptの設定
12.WordPress用DBの作成
13WordPress(2個目)のインストール
14.ユーザーの作成と権限の付与
15.Wp-configの設定
9. 域名服务器的设置 (Yǔmíng fúwǔ qì de进行域名服务器和VPS服务器的设置。有两种方法可使用”お名前ドットコム”的域名服务器或使用”さくら”的域名服务器。虽然步骤不同,但两种方法都可以,您可以根据喜好进行设置。
手順は下記が参考になります。
お名前.comで取得したドメインをさくらVPSで使う
如果您认为名称服务器配置不正确,请等待一段时间(最多72小时),然后再次确认。
10. Apache的虚拟主机配置接下来,我们将设置Apache的虚拟主机。
虚拟主机是指在一个虚拟专用服务器(VPS)上可以运营多个域名的系统。
root権限で作業してください。
まず、バーチャルホスト用のディレクトリを作成します。
追加したドメイン(example.net)のコンテンツを置くディレクトリです。
# mkdir /var/www/html/example.net
# chown vpsuser /var/www/html/example.net (ディレクトリのオーナーをvpsuserに変更)
创建目录后,在/etc/httpd/conf.d中创建名为vhost.conf的文件,并写入虚拟主机的配置。
# vi /etc/httpd/conf.d/vhost.conf
//1個目のドメインexample.comの設定
<VirtualHost *:80>
ServerName example.com
DirectoryIndex index.html
AddDefaultCharset UTF-8
DocumentRoot /var/www/html //1個目のWordPressが入っているディレクトリを記入してください
<Directory "/var/www/html"> //1個目のWordPressが入っているディレクトリを記入してください
Require all granted
</Directory>
</VirtualHost>
//2個目のドメインexample.comの設定
<VirtualHost *:80>
ServerName example.net
DirectoryIndex index.html
AddDefaultCharset UTF-8
DocumentRoot /var/www/html/example.net //作成したディレクトリを記入してください
<Directory "/var/www/html/example.net"> //作成したディレクトリを記入してください
Require all granted
</Directory>
</VirtualHost>
完成后,请重新启动Apache以使设置生效。
# systemctl reload httpd
顺便一提,重新启动会停止所有进程(WEB服务),然后再启动,所以网站会短暂下线。
若要避免网站下线且安全地重新加载设置,可以使用reload命令或graceful命令。
参考:Apache的配置文件(httpd.conf)安全重新加载的方法。
此外,在CentOS7中,使用systemctl reload httpd命令,而不是CentOS6之前的service httpd reload命令。
参考:总结了关于启动、停止和重启apache的方法。
当设置生效后,输入http://example.com和http://example.net时,将显示不同的页面。
11. 让我们设置Let’s Encrypt
つづいて、サイトのページを暗号化通信で安全に公開するために、常時SSLの設定をしていきます。
簡単に言うと、URLのhttpをhttpsにする設定です。
無料のSSL証明書発行サービスであるLet’s Encryptというサービスを利用します。
首先,将SSL设置添加到/etc/httpd/conf.d目录下的vhost.conf文件中,这是刚刚创建的文件。
# vi /etc/httpd/conf.d/vhost.conf
<VirtualHost *:80>
ServerName example.com
DirectoryIndex index.html
AddDefaultCharset UTF-8
DocumentRoot /var/www/html
//httpでアクセスがあった場合に、リダイレクトさせる指示
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</IfModule>
<Directory "/var/www/html">
Require all granted
</Directory>
</VirtualHost>
//SSLの設定を追記
<VirtualHost *:443>
ServerName example.com
DocumentRoot /var/www/html
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/exapmle.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/exapmle.com/fullchain.pem
</VirtualHost>
<VirtualHost *:80>
ServerName example.net
DirectoryIndex index.html
AddDefaultCharset UTF-8
DocumentRoot /var/www/html/example.net
//httpでアクセスがあった場合に、リダイレクトさせる指示
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</IfModule>
<Directory "/var/www/html/example.net">
Require all granted
</Directory>
</VirtualHost>
//SSLの設定を追記
<VirtualHost *:443>
ServerName example.net
DocumentRoot /var/www/html/example.net
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/example.com/fullchain.pem
</VirtualHost>
编辑完后,重新启动Apache以使配置生效。
# systemctl reload httpd
その後、certbotコマンドを実行して、SSL証明書をインストールします。
–webroot -wでディレクトリを指定し、-dでドメインを指定します。
certbotコマンドは、バージョンによって使えないことがあるので、適宜変更してください。(コマンドはググれば出てきます)
# certbot certonly --webroot -w /var/www/html -d example.com -w /var/www/html/example.net -d example.net
請回答「是的」,如果在第一次安裝WordPress時已經發行了SSL證書,系統會詢問是否要擴展(expand)。
一旦完成后,http://example.com和https://example.com,http://example.net和https://example.net将分别能够访问同一个页面。
12. 创建WordPress使用的数据库MySQLで、追加するWordPress用のデータベースを作成します。
MySQLをインストールしていない場合は、下記のページを参考に設定してください。
MySQLの設定(CentOS 7)
MySQLにrootでログインして、データベースの作成と権限の付与を行います。
# mysql -u root -p
Enter password:
mysql> create database example_net_db;
mysql> grant all privileges on examplen_net_db.* to 'example_net_user'@'localhost';
mysql> flush privileges;
mysql> exit
//ここでは、examplen_net_dbがデータベース名、example_net_userがユーザーネームです
在从MySQL登出后,使用用户名example_net_user登录并确认数据库已经创建。
# mysql -u example_net_user -p
Enter password:
mysql> show databases;
+-----------------------+
| Database |
+-----------------------+
| examplen_net_db |
| information_schema |
| mysql |
| performance_schema |
| sys |
| wordpressdb |
+-----------------------+
6 rows in set (0.02 sec)
mysql> exit
13 WordPress(第二个)的安装ここまできたら、いよいよ2個目のWordPressをインストールしていきます。
まず、WordPressの公式サイト(https://ja.wordpress.org/download/)で、最新のWordPressファイル(.tar.gz形式)をダウンロードします。
ローカルを経由せず、直接サーバーにダウンロードする場合は、wgetコマンドを使います。
# wget https://ja.wordpress.org/latest-ja.tar.gz
# tar -xzvf latest-ja.tar.gz
http://xxx.xxx.xxx.xxx/wordpressではなく、http://xxx.xxx.xxx.xxx/でWordPressにアクセスできるようにしたいので、wordpressディレクトリの下にあるすべてのファイルを、ドメインexample.netのドキュメントルート/var/www/html/example.netにmvコマンドで移動させます。
# mv wordpress/* /var/www/html/example.net
# rmdir wordpress
14. 创建用户并授予权限つづいて、さきほどインストールしたWordPressファイルが、apacheユーザー、vpsuserユーザーのいずれでも更新できるようにするため、すべてのファイルの所有者をapacheにして、グループをvpsuserにします。
そしてグループに書き込み権限をつけておきます。
# chown -R apache:vpsuser *
# chmod -R g+w *
15. Wp-config的配置
さいごに、WordPressの基本設定を行うwp-config.phpの編集を行います。
wp-config-sample.phpというファイルがあるので、そのファイルをコピーしてwp-config.phpを作成、編集していきます。
# cd /var/www/html/example.net
# cp wp-config-sample.php wp-config.php
# vi wp-config.php
将数据库名称、用户名和密码字段分别更改为设定的值。
define('DB_NAME', 'examplen_net_db');
/** MySQL database username */
define('DB_USER', 'examplen_net_user');
/** MySQL database password */
define('DB_PASSWORD', 'password for examplen_net_user');
/** MySQL hostname */
define('DB_HOST', 'localhost');
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');
/**#@+
* Authentication Unique Keys and Salts.
*
* Change these to different unique phrases!
* You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
* You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
*
* @since 2.6.0
*/
define('AUTH_KEY', '*');
define('SECURE_AUTH_KEY', '*');
define('LOGGED_IN_KEY', '*');
define('NONCE_KEY', '*');
define('AUTH_SALT', '*');
define('SECURE_AUTH_SALT', '*');
define('LOGGED_IN_SALT', '*');
define('NONCE_SALT', '*');
下から8行のAUTH_KEYなどは、Authentication Unique Keys(認証キー)で、https://api.wordpress.org/secret-key/1.1/salt/が出力する64桁のランダムな文字列を入力します。
执行安装脚本完成WordPress安装配置,访问https://example.net/wp-admin/install.php后,出现WordPress安装页面时,请填写网站名称等信息,进行安装。
参考网站
-
複数のウェブサイトを1つのVPS上に作るための環境作り(Apache + MySQL + PHP + WordPress / Ubuntu / Linode)
-
ネコでもわかる!さくらのVPS講座 〜第一回:VPSてなんだろう?〜
-
お名前.comで取得したドメインをさくらVPSで使う
-
Apacheの設定ファイル(httpd.conf)を安全に読み込む方法
apacheの起動,停止,再起動に関するまとめ
使用的是独立域名,使用的是”お名前ドットコム”。
从Sakura VPS契约到安装WordPress的步骤さくらのVPSを契約してから、サーバーの初期設定、WordPressインストールまでの流れは下記のとおりです。
今回は、すでにWordPressを1つインストールしている状態なので、手順8以降を設定していきます。
1.さくらのVPS契約
2.標準OSのインストール(CentOS7)
3.Apache(もしくはnginx)をインストール
4.PHPインストール
5.MySQL(もしくはMariaDB)をインストール
6.phpMyAdminをインストール(※必須ではない)
7.ファイアウォールの設定(※自動で有効になる)
//ここから追加設定
8.独自ドメインの取得(example.net)
9.ネームサーバーの設定
10.Apacheのバーチャルホスト設定
11.Let’s Encryptの設定
12.WordPress用DBの作成
13WordPress(2個目)のインストール
14.ユーザーの作成と権限の付与
15.Wp-configの設定
9. 域名服务器的设置 (Yǔmíng fúwǔ qì de进行域名服务器和VPS服务器的设置。有两种方法可使用”お名前ドットコム”的域名服务器或使用”さくら”的域名服务器。虽然步骤不同,但两种方法都可以,您可以根据喜好进行设置。
1.さくらのVPS契約
2.標準OSのインストール(CentOS7)
3.Apache(もしくはnginx)をインストール
4.PHPインストール
5.MySQL(もしくはMariaDB)をインストール
6.phpMyAdminをインストール(※必須ではない)
7.ファイアウォールの設定(※自動で有効になる)
//ここから追加設定
8.独自ドメインの取得(example.net)
9.ネームサーバーの設定
10.Apacheのバーチャルホスト設定
11.Let’s Encryptの設定
12.WordPress用DBの作成
13WordPress(2個目)のインストール
14.ユーザーの作成と権限の付与
15.Wp-configの設定
手順は下記が参考になります。
お名前.comで取得したドメインをさくらVPSで使う
如果您认为名称服务器配置不正确,请等待一段时间(最多72小时),然后再次确认。
10. Apache的虚拟主机配置接下来,我们将设置Apache的虚拟主机。
虚拟主机是指在一个虚拟专用服务器(VPS)上可以运营多个域名的系统。
root権限で作業してください。
まず、バーチャルホスト用のディレクトリを作成します。
追加したドメイン(example.net)のコンテンツを置くディレクトリです。
# mkdir /var/www/html/example.net
# chown vpsuser /var/www/html/example.net (ディレクトリのオーナーをvpsuserに変更)
创建目录后,在/etc/httpd/conf.d中创建名为vhost.conf的文件,并写入虚拟主机的配置。
# vi /etc/httpd/conf.d/vhost.conf
//1個目のドメインexample.comの設定
<VirtualHost *:80>
ServerName example.com
DirectoryIndex index.html
AddDefaultCharset UTF-8
DocumentRoot /var/www/html //1個目のWordPressが入っているディレクトリを記入してください
<Directory "/var/www/html"> //1個目のWordPressが入っているディレクトリを記入してください
Require all granted
</Directory>
</VirtualHost>
//2個目のドメインexample.comの設定
<VirtualHost *:80>
ServerName example.net
DirectoryIndex index.html
AddDefaultCharset UTF-8
DocumentRoot /var/www/html/example.net //作成したディレクトリを記入してください
<Directory "/var/www/html/example.net"> //作成したディレクトリを記入してください
Require all granted
</Directory>
</VirtualHost>
完成后,请重新启动Apache以使设置生效。
# systemctl reload httpd
顺便一提,重新启动会停止所有进程(WEB服务),然后再启动,所以网站会短暂下线。
若要避免网站下线且安全地重新加载设置,可以使用reload命令或graceful命令。
参考:Apache的配置文件(httpd.conf)安全重新加载的方法。
此外,在CentOS7中,使用systemctl reload httpd命令,而不是CentOS6之前的service httpd reload命令。
参考:总结了关于启动、停止和重启apache的方法。
当设置生效后,输入http://example.com和http://example.net时,将显示不同的页面。
11. 让我们设置Let’s Encrypt
つづいて、サイトのページを暗号化通信で安全に公開するために、常時SSLの設定をしていきます。
簡単に言うと、URLのhttpをhttpsにする設定です。
無料のSSL証明書発行サービスであるLet’s Encryptというサービスを利用します。
首先,将SSL设置添加到/etc/httpd/conf.d目录下的vhost.conf文件中,这是刚刚创建的文件。
# vi /etc/httpd/conf.d/vhost.conf
<VirtualHost *:80>
ServerName example.com
DirectoryIndex index.html
AddDefaultCharset UTF-8
DocumentRoot /var/www/html
//httpでアクセスがあった場合に、リダイレクトさせる指示
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</IfModule>
<Directory "/var/www/html">
Require all granted
</Directory>
</VirtualHost>
//SSLの設定を追記
<VirtualHost *:443>
ServerName example.com
DocumentRoot /var/www/html
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/exapmle.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/exapmle.com/fullchain.pem
</VirtualHost>
<VirtualHost *:80>
ServerName example.net
DirectoryIndex index.html
AddDefaultCharset UTF-8
DocumentRoot /var/www/html/example.net
//httpでアクセスがあった場合に、リダイレクトさせる指示
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</IfModule>
<Directory "/var/www/html/example.net">
Require all granted
</Directory>
</VirtualHost>
//SSLの設定を追記
<VirtualHost *:443>
ServerName example.net
DocumentRoot /var/www/html/example.net
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/example.com/fullchain.pem
</VirtualHost>
编辑完后,重新启动Apache以使配置生效。
# systemctl reload httpd
その後、certbotコマンドを実行して、SSL証明書をインストールします。
–webroot -wでディレクトリを指定し、-dでドメインを指定します。
certbotコマンドは、バージョンによって使えないことがあるので、適宜変更してください。(コマンドはググれば出てきます)
# certbot certonly --webroot -w /var/www/html -d example.com -w /var/www/html/example.net -d example.net
請回答「是的」,如果在第一次安裝WordPress時已經發行了SSL證書,系統會詢問是否要擴展(expand)。
一旦完成后,http://example.com和https://example.com,http://example.net和https://example.net将分别能够访问同一个页面。
12. 创建WordPress使用的数据库MySQLで、追加するWordPress用のデータベースを作成します。
MySQLをインストールしていない場合は、下記のページを参考に設定してください。
MySQLの設定(CentOS 7)
MySQLにrootでログインして、データベースの作成と権限の付与を行います。
# mysql -u root -p
Enter password:
mysql> create database example_net_db;
mysql> grant all privileges on examplen_net_db.* to 'example_net_user'@'localhost';
mysql> flush privileges;
mysql> exit
//ここでは、examplen_net_dbがデータベース名、example_net_userがユーザーネームです
在从MySQL登出后,使用用户名example_net_user登录并确认数据库已经创建。
# mysql -u example_net_user -p
Enter password:
mysql> show databases;
+-----------------------+
| Database |
+-----------------------+
| examplen_net_db |
| information_schema |
| mysql |
| performance_schema |
| sys |
| wordpressdb |
+-----------------------+
6 rows in set (0.02 sec)
mysql> exit
13 WordPress(第二个)的安装ここまできたら、いよいよ2個目のWordPressをインストールしていきます。
まず、WordPressの公式サイト(https://ja.wordpress.org/download/)で、最新のWordPressファイル(.tar.gz形式)をダウンロードします。
ローカルを経由せず、直接サーバーにダウンロードする場合は、wgetコマンドを使います。
# wget https://ja.wordpress.org/latest-ja.tar.gz
# tar -xzvf latest-ja.tar.gz
# wget https://ja.wordpress.org/latest-ja.tar.gz
# tar -xzvf latest-ja.tar.gz
http://xxx.xxx.xxx.xxx/wordpressではなく、http://xxx.xxx.xxx.xxx/でWordPressにアクセスできるようにしたいので、wordpressディレクトリの下にあるすべてのファイルを、ドメインexample.netのドキュメントルート/var/www/html/example.netにmvコマンドで移動させます。
# mv wordpress/* /var/www/html/example.net
# rmdir wordpress
14. 创建用户并授予权限つづいて、さきほどインストールしたWordPressファイルが、apacheユーザー、vpsuserユーザーのいずれでも更新できるようにするため、すべてのファイルの所有者をapacheにして、グループをvpsuserにします。
そしてグループに書き込み権限をつけておきます。
# chown -R apache:vpsuser *
# chmod -R g+w *
15. Wp-config的配置
さいごに、WordPressの基本設定を行うwp-config.phpの編集を行います。
wp-config-sample.phpというファイルがあるので、そのファイルをコピーしてwp-config.phpを作成、編集していきます。
# cd /var/www/html/example.net
# cp wp-config-sample.php wp-config.php
# vi wp-config.php
# chown -R apache:vpsuser *
# chmod -R g+w *
さいごに、WordPressの基本設定を行うwp-config.phpの編集を行います。
wp-config-sample.phpというファイルがあるので、そのファイルをコピーしてwp-config.phpを作成、編集していきます。
# cd /var/www/html/example.net
# cp wp-config-sample.php wp-config.php
# vi wp-config.php
将数据库名称、用户名和密码字段分别更改为设定的值。
define('DB_NAME', 'examplen_net_db');
/** MySQL database username */
define('DB_USER', 'examplen_net_user');
/** MySQL database password */
define('DB_PASSWORD', 'password for examplen_net_user');
/** MySQL hostname */
define('DB_HOST', 'localhost');
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');
/**#@+
* Authentication Unique Keys and Salts.
*
* Change these to different unique phrases!
* You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
* You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
*
* @since 2.6.0
*/
define('AUTH_KEY', '*');
define('SECURE_AUTH_KEY', '*');
define('LOGGED_IN_KEY', '*');
define('NONCE_KEY', '*');
define('AUTH_SALT', '*');
define('SECURE_AUTH_SALT', '*');
define('LOGGED_IN_SALT', '*');
define('NONCE_SALT', '*');
下から8行のAUTH_KEYなどは、Authentication Unique Keys(認証キー)で、https://api.wordpress.org/secret-key/1.1/salt/が出力する64桁のランダムな文字列を入力します。
执行安装脚本完成WordPress安装配置,访问https://example.net/wp-admin/install.php后,出现WordPress安装页面时,请填写网站名称等信息,进行安装。
参考网站
-
複数のウェブサイトを1つのVPS上に作るための環境作り(Apache + MySQL + PHP + WordPress / Ubuntu / Linode)
-
- 複数のウェブサイトを1つのVPS上に作るための環境作り(Apache + MySQL + PHP + WordPress / Ubuntu / Linode)
-
- ネコでもわかる!さくらのVPS講座 〜第一回:VPSてなんだろう?〜
-
- お名前.comで取得したドメインをさくらVPSで使う
-
- Apacheの設定ファイル(httpd.conf)を安全に読み込む方法
- apacheの起動,停止,再起動に関するまとめ