- 追加された行はこの色です。
- 削除された行はこの色です。
#author("2016-07-10T17:08:09+09:00","default:wikiwriter","wikiwriter")
#author("2017-04-03T18:31:13+09:00","default:wikiwriter","wikiwriter")
[[Nginx]]
&tag(Nginx/設定);
*目次 [#bc5e42a0]
#contents
*関連ページ [#u1e285ac]
*参考情報 [#w2825af1]
-[[Nginx + php-fpm をさくらのVPSで使ってみた | レンタルサーバー・自宅サーバー設定・構築のヒント:http://server-setting.info/centos/apache-nginx-9-sakura-vps.html]]…コア数の設定など
-[[Nginxを使ったもう一歩進んだWordPressチューニング | cloudrop:http://cloudrop.jp/wordpress/more_tuning_on_nginx]]
*設定の基本 [#u41194c9]
-CentOS6の場合/etc/nginx/conf.d/default.confを編集。
*PHP-FPMとの連携 [#x013328e]
-CentOS6の場合default.confを以下のように設定する。最後のlocationディレクティブが肝心。
#pre{{
server {
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
(以下中略)
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}}
-ポート番号を変える場合iptablesで穴を買えることを忘れないように。locationディレクティブでrootとfastcgi_paramを変更すること。
-/etc/php-fpm.d/www.confの編集。Unix Socketを使う場合さらなる変更が必要。
#pre{{
user = nginx
group = nginx
}}
**Unix Socketで連携 [#u1eae7b4]
-/etc/php-fpm.d/www.confの編集
listen = /var/run/php-fpm/www.sock
-/etc/nginx/conf.d/default.confの編集。先頭にunixが必要なことに注意。
fastcgi_pass unix:/var/run/php-fpm/www.sock
*WordPress用の設定(ルート) [#b2b4c6c1]
**設定ファイル [#r5d5d352]
-サブディレクトリ運用ははまりやすいのでルートで運用するのが簡単。
-default.confのサンプル。
#pre{{
server {
listen 8080;
server_name centos6maroon;
index index.php;
root /home/sora/public_html/wp2;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~* /wp-config.php {
deny all;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}}
-http://centos6maroon:8080を開く。
**php-fpmの設定 [#j8ac159e]
-[[CentOS php-fpmの設定を変更してメモリ消費を減らした方法 | CrystalSnowman.com:http://www.crystalsnowman.com/?p=1309]]
#pre{{
pm = dynamic
pm.max_children = 10
pm.max_children = 8
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 6
pm.max_requests = 500
}}
**トラブルシューティング [#z8705cda]
-PHPがダウンロードされてきた: 設定が正しい場合ブラウザのキャッシュの可能性あり。他のブラウザやcurlで試してみる。
-forbiddonが表示された: try_filesの設定かも?
*WordPress用の設定(サブディレクトリ) [#d51c884e]
-[[nginxでサブディレクトリに配置したWordpressが動かないや -> パーマリンクの設定だった - 珈琲駆動開発:http://totutotu.hatenablog.com/entry/2015/10/25/nginx%E3%81%A7%E3%82%B5%E3%83%96%E3%83%87%E3%82%A3%E3%83%AC%E3%82%AF%E3%83%88%E3%83%AA%E3%81%AB%E9%85%8D%E7%BD%AE%E3%81%97%E3%81%9FWordpress%E3%81%8C%E5%8B%95%E3%81%8B%E3%81%AA%E3%81%84%E3%82%84_-%3E_]] PENDING