環境
Webサーバ : nginx
Webアプリ : Laravel5
解決したいこと
nginxの設定ファイルの書き方について悩んでおります。
http://example.com/
http://example.com/test/
へのアクセスをサブディレクトリに配備したアプリケーションで処理したいです。
それぞれ処理したいアプリケーションへは http://example.com/app/
, http://example.com/app/some_controller
で直にアクセスできます。
nginxの設定において、ベストプラクティスのようなものがあれば教えていただきたいです。
nginx設定ファイル
以下の2通りの設定を試し、どちらも動作は確認できています。
上記を実現する場合、どちらがより良い書き方になるのでしょうか?
また、他の書き方や注意すべき点などはありますでしょうか?
リライトの数も増えていく予定ですので、シンプルかつ修正もしやすくしたいです。
location / { location /test { proxy_pass http://$server_name/app/some_controller; } proxy_pass http://$server_name/app/$1; }
location / { proxy_pass http://$server_name/app/$1; } location = /test { proxy_pass http://$server_name/app/some_controller; }
server { listen 80; server_name example.com; rewrite ^(.+)/$ $1; include /etc/nginx/conf.d/rewrite.conf; # 上記設定はここでinclude location ~ ^/app(/(.+))?$ { root /opt/app/public; try_files $1 /app/index.php?$query_string; location ~ ^/app/index.php$ { include fastcgi_params; fastcgi_param SCRIPT_FILENAME /opt/app/public/index.php; fastcgi_split_path_info ^(.+\.php)(.+)$; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_read_timeout 180; } } }
###補足情報(言語/FW/ツール等のバージョンなど)
Laravelのルーティングは以下のとおりです。
php
1<?php 2 3Route::get('/',['uses' => 'HomeController@getIndex']); 4 5Route::any('/some_controller1', ['uses' => 'SomeController1@index', 'as' => 'c1']); 6Route::any('/some_controller2', ['uses' => 'SomeController2@index', 'as' => 'c2']); 7Route::any('/some_controller3/{param}', ['uses' => 'SomeController3@getIndex', 'as' => 'c3']); 8Route::any('/some_controller4/{param}', ['uses' => 'SomeController4@getIndex', 'as' => 'c4']);
あなたの回答
tips
プレビュー