nginx+php-fpm+wordpress

マルチサイトで運用中の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

kashioka

有限会社アリウープ 代表取締役社長 PHPユーザ会の発起人の一人。いちばんやさしいPHPの教本(インプレス),PHPハンドブック(ソフトバンククリエイティブ)著者。PHPカンファレンス実行委員 明日の開発カンファレンス開催 認定スクラムマスター。近年、PHPに限らずサーバレス環境でのPythonなども書いたりしている。 http://alleyoop.jp

%d人のブロガーが「いいね」をつけました。