nginxのサイトを作るたびに*.phpだと動くけど、*.htmlに変えると真っ白とか
*.phpでも実行されずにダウンロードされたりするので忘れすぎ。
忘れないようにメモ
環境
CentOS 6.8 final
nginx 1.10.1
PHP 5.6.22
nginxはmainline版をyumインストール
PHPはepel,remiリポジトリを追加してremiの最新版をyumインストール
php-fpmの設定ファイル変更点
/etc/php-fpm.d/www.conf
user = nginx
group = nginx
listen = /var/run/php-fpm/php-fpm.sock
listen.mode = 660
security.limit_extensions = .php .html
nginxの設定ファイル変更点
/etc/nginx/conf.d/server.conf
location /{
root /usr/share/nginx/html;
index index.php index.html;
}
location ~\.(php|html)${
root /usr/share/nginx/html;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include fastcgi_params;
}
他にやること
まだ動かないとき、ログを見るとphp-fpmがparmission deniedとなってるので
#sudo chmod 666 /var/run/php-fpm/php-fpm.sock
これで .phpファイルも、.htmlファイル内でで囲った部分も実行される。
セキュリティのためらしいので666にするなら注意
iptablesが動いてるとダメなこともあるので止めること
#sudo /etc/init.d/iptables stop
#sudo /etc/init.d/ip6tables stop
#sudo chkconfig iptables off
#sudo chkconfig ip6tables off