環境構築時に見直すファイル箇所を把握するのに時間がかかったためメモ。
突発的になる An error occurred に関してはここでは触れない。
PHP 側
下記変更する箇所。
$ sudo vi /etc/php-fpm.d/www.conf
;user = apache
user = nginx
;group = apache
group = nginx
;listen = 127.0.0.1:9000
listen = /var/run/php-fpm/php-fpm.sock
;listen.owner = nobody
;listen.group = nobody
;listen.mode = 0660
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
Nginx
$ sudo vi /etc/nginx.conf.d/your-project.conf
server {
listen 80;
server_name your.project.com;
root /var/www/html/to/your/project;
index index.php index.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# PHP FPM の設定
#
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index /index.php;
include /etc/nginx/fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# PHP フレームワークを使う時。大体この設定
#
try_files $uri $uri/ @rewrite;
location @rewrite {
rewrite ^(.*)$ /index.php?_url=$1;
}
# 静的にアクセスしたいディレクトリを指定
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root /var/www/html/to/your/project;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}