nginx と php-fpm 間の通信には、Unix socket通信が使用できます。 ここでは、Unix socket通信で使用するファイルを以下としています。
/var/run/php-fpm/php-fpm.sockこれは、nginxとphp-fpmの設定ファイルで指定する必要があります。
php-fpmの設定は、以下を参照
設定
nginx.confのserver項目に、php-fpm用の設定を行います。
例
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
この例では、拡張子が ".php" の場合、php-fpm を使用するようになっています。
また、"location /" の設定も変更します。Laravel 6では、以下のように設定しています。
location / {
try_files $uri $uri/ /index.php?$query_string;
}
設定例
nginx.conf
例 Laravel6用のserver設定
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /var/www/html/public
index index.php index.html;
charset UTF-8;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}