参考
概要
すでに既存のシステムがexample.comとして稼働している状態で、example.com/laraveltest
にアクセスした場合は、処理をlaravelに任せたい。
基本的にはnginxのconfを修正するのみ。
なお、LinuxMintの場合、nginxのデフォルト設定は/etc/nginx/sites-available/default
となっている。(apt-getでインストールした場合)
実際のconfの内容
以下のlocation ~ ^/laraveltest((/)?(.+))?$ {
で始まっているlocationディレクティブを追加するのみ。
追加したらnginx -s reload
で再起動すれば、example.com/laraveltest
にアクセスするとちゃんとlaravelアプリケーションが動作する。
/etc/nginx/sites-available/default
server {
#...省略
#ここを追加する。
location ~ ^/laraveltest((/)?(.+))?$ {
root /var/www/nginx/laraveltest/public;
try_files $1 /laraveltest/index.php?$query_string;
location ‾ ^/laraveltest/index.php$ {
include fastcgi_params;
#try_files $uri = 404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param PATHINFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_split_path_info ^(.+¥.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
}
}
# ... 省略
}
ディレクトリ名とURLを分けたい場合
URLは/laraveltest
にしたいけど、Laravel自体はhoge
というディレクトリにあるんだよね〜という場合は、単純にrootディレクティブを以下のように変更するのみ。
/etc/nginx/sites-available/default
root /var/www/nginx/hoge/public