マルチサイトで運用中のWordPressサーバが重くなってきたので、nginxの導入を行いました。
cent OSに入れるのでyumでインストールします。remiのリポジトリ使います。
現在はApacheとphpで動いています。
$sudo yum -y install nginx php-cli php-fpm –enablerepo=remi
インストールが完了したら
/etc/nginx/nginx.confを編集
バーチャルドメインの場合は/etc/nginx/conf.d/以下にapacheの設定のようにヴァーチャルドメインを追加する。
conf.d以下がnginx.confに読み込まれるので、拡張子は.confにする必要がある # Load config files from the /etc/nginx/conf.d directory include /etc/nginx/conf.d/*.conf; こんな感じで読み込まれるため /etc/nginx/conf.d/example.com.confとかserver { #WordPressマルチサイト listen 80; server_name example.com www.example.com example.net www.example.net; access_log /var/log/nginx/access_log; error_log /var/log/nginx/error_log; index index.php index.html; location ~ .*.php$ { root /var/www/example/htdocs; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } //パーマリンク location / { try_files $uri $uri/ /index.php?q=$uri&$args; } //マルチサイト rewrite ^.*/files/(.*) /wp-includes/ms-files.php?file=$1; }もしCLI版を有効にしていなければ、php.ini等でapc.enable_cli=1を追記してください。
/etc/php-fpm.d/www.conf
user=nginx; group=nginx;userとgroupはwordpressのディレクトリパーミッションにより 柔軟に対応してください。 uploads等を777にしている場合はどのユーザでもOK apacheユーザやnobodyユーザへのみ書き込みを開けているユーザに変更する(擬似apache化w) server_tokens off; 等の設定を行う。/etc/rc.d/init.d/httpd stop /etc/rc.d/init.d/nginx start
/etc/rc.d/init.d/php-fmp
これで起動 nginxでwordpressが動きます。
参考サイト
さくらのVPS CentOSでサーバ構築 21 – Nginx 楽しく情報処理技術者試験
Published by