経緯
上記環境でLaravelアプリケーションが動かなかった
(トップページは表示されたものの、ログインページが 404 Not Found となった)
ので、設定ファイルを変更したときのメモ。
Mac、Nginx、php-fpm7.2構築方法はこちら
macにbrewでnginxとPHP7.2をインストールした
https://qiita.com/uneri/items/46bfeeabf77d76abb3ba
概要
Nginxのデフォルトの設定ファイルをコピーして、以下2箇所を書き換える。
詳細
デフォルトの設定ファイルをコピー
cd /usr/local/etc/nginx/
cp nginx.conf.default nginx.conf
vim nginx.conf
1箇所目
変更前
nginx.conf
location / {
root html;
index index.html index.htm;
}
変更後(xxxxはアプリケーションのパス)
nginx.conf
location / {
root /usr/local/var/www/xxxx/public;
index index.php index.html
try_files $uri $uri/ /index.php;
}
2箇所目
変更前
nginx.conf
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
変更後(xxxxはアプリケーションのパス)
nginx.conf
location ~ \.php$ {
root /usr/local/var/www/xxxx/public;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Nginxを再起動する
brew services restart nginx
ブラウザでアプリケーションにアクセスする
参考にした情報
All Laravel routes "not found" on nginx
https://www.digitalocean.com/community/questions/all-laravel-routes-not-found-on-nginx
MacでNingx、PHP7.1、php-fpmで環境構築(メモ)
https://qiita.com/nogizaka46/items/42a6ea1c634985f98564