ãããã¨ããã¾ã§ãã£ã¦ã¿ãã nginx config
- åæ
- æ¢ç¥é¨åã®ç¢ºèª
- æªããç®ãªæ¢ç¥é¨åã®ç¢ºèª
- æªç¥é¨åã¸ã®è¸ã¿è¾¼ã¿
- æªç¥ã®æ¬çª
åæ
http { # ãããã°ç¨ log_format debug "[DEBUG][$time_local] $debug_data";
ã使ãã¨ãããã°ãããã®ã§ãnginx.conf ã«ä»è¾¼ãã§ããã
/home/gallu/test
ã£ã¦ãã£ã¬ã¯ããªãç¨æãã¦ããããèµ·ç¹ã«ãã(ãã¨ã§è¿½å ãããã©)ã
æ¢ç¥é¨åã®ç¢ºèª
é²è¦§ã§ããããã«ãã
server { listen 80; server_name dev.example.net; access_log /var/log/nginx/dev.example.net.access.log main; error_log /var/log/nginx/dev.example.net.error.log; # root /home/gallu/test/; set $debug_data ""; #access_log /var/log/nginx/debug.log debug; }
ããã¾ãæ®éã«è¦ããã
location ã§ããã£ã¦ãã
server { listen 80; server_name dev.example.net; access_log /var/log/nginx/dev.example.net.access.log main; error_log /var/log/nginx/dev.example.net.error.log; # location / { root /home/gallu/test/; } set $debug_data ""; #access_log /var/log/nginx/debug.log debug; }
OKã
ãã£ã¬ã¯ããªã«ãã£ã¦ã¯ãå¥ã®DocumentRootãè¦ããããã«ãã
server { listen 80; server_name dev.example.net; access_log /var/log/nginx/dev.example.net.access.log main; error_log /var/log/nginx/dev.example.net.error.log; # location /foo/ { alias /home/gallu/test2/; } # location / { root /home/gallu/test/; } set $debug_data ""; #access_log /var/log/nginx/debug.log debug; }
ãããOKã
ãªãã /foo/ ã®æãrootã«ããã¨ä¸æããããªãã®ã§aliasã«ããã¨ããã§ãã
ç´°ããããã㯠"nginx root alias" ãããã§ã°ã°ãã¨è²ã
åºã¦ããã®ã§çç¥ã
ã¡ãã£ã¨ãã®è¾ºãã§å¤å°ãªããããã°ãã°åºãã¦ã¿ããã
setã®ä½ç½®ééããã¨è²ã
é½é½¬ãã£ã½ãã®ã§ãå°ããã®è¾ºä¿®æ£ã
server { listen 80; server_name dev.example.net; access_log /var/log/nginx/dev.example.net.access.log main; error_log /var/log/nginx/dev.example.net.error.log; # location /foo/ { alias /home/gallu/test2/; set $debug_data "$document_root $request_uri $uri"; } # location / { root /home/gallu/test/; set $debug_data "$document_root $request_uri $uri"; } # access_log /var/log/nginx/debug.log debug; }
ããã§
[DEBUG][24/Feb/2023:16:43:22 +0900] /home/gallu/test / /index.html
[DEBUG][24/Feb/2023:16:43:30 +0900] /home/gallu/test2/ /foo/ /foo/index.html
ã£ã¦åºã¦ããã®ã§ãã¾ã大ä½æå³éãã
index.htmlãåæã«ä»ä¸ããã¦ããã®ããã£ããæ°ã«ãªãã®ã§ä¸å¿è»½ã調ã¹ã¦ã¿ãã
http://mogile.web.fc2.com/nginx/http/ngx_http_index_module.html#index
â¦â¦ãããããã©ã«ããindex.htmlãã«ãªã£ã¦ãã£ã½ãã®ã§ããããç´å¾ã
ããã§
ã»rootã¨ãaliasã¨ãã§ãæå³éãã®document_rootã«ãªã£ã¦ãã
ã»$request_uriã«ã¯ããªã¯ã¨ã¹ãæã®URI(ã®path以éé¨å)ããå
¥ã£ã¦ã
ã»$uriã«ã¯ã(ä»åã¯ãindexã§è£å®ããã)pathåãå
¥ã£ã¦ããã
ãããã¾ã§ãæ
ä¿ã§ãã¦ãæãã
ä¸å¿ãå¤æ°ã®ãã¨ã調ã¹ã¦ããã
http://nginx.org/en/docs/http/ngx_http_core_module.html
$document_root root or alias directiveâs value for the current request
$request_uri full original request URI (with arguments)
$uri current URI in request, normalized
ãã大ä½èªèä¸è´ã
ãuriã¯normalizedããã¦ãããããindexã§è£å®ããã¦ããã ãã
æªããç®ãªæ¢ç¥é¨åã®ç¢ºèª
ãã¦ãã¾ãã¯åç´ã«ãPHPãåãããããã
ãªãã¨ãªããã£ããæ¸ãã¦ã¿ãã
fastcgi_passã§php-fpmã®æå®ãincludeã§ãå¿
è¦ãªè«¸ã
ã®ãã¼ã¿ãã®è¨å®ãfastcgi_indexã§ã¯ãpathããã£ã¬ã¯ããªã ãã®æã®ããã©ã«ãã®indexãã¡ã¤ã«åããfastcgi_param SCRIPT_FILENAMEã§ãSCRIPT_FILENAMEã®è¨å®ã®ä¸æ¸ã(fastcgi.confã«ãæ¸ãã¦ãããã)ãã
server { listen 80; server_name dev.example.net; access_log /var/log/nginx/dev.example.net.access.log main; error_log /var/log/nginx/dev.example.net.error.log; # location /foo/ { alias /home/gallu/test2/; set $debug_data "foo) $document_root $request_uri $uri"; } # location / { root /home/gallu/test/; set $debug_data "/) $document_root $request_uri $uri"; } # location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; include fastcgi.conf; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; set $debug_data "/ php) $document_root $request_uri $uri $fastcgi_script_name"; } # access_log /var/log/nginx/debug.log debug; }
ã§â¦â¦é§ç®ã
[DEBUG][24/Feb/2023:18:16:17 +0900] / php) /usr/share/nginx/html /t.php /t.php /t.php
ã»ãâ¦â¦document_rootããæå³ãã¦ãã location / ãããªãã¦ãããã©ã«ãåãã¦ãããã
locationã®è¨å®ããªãã¨ãªãã1ã¤ãããé¸ã°ããªãããã ã¨ããã¨ãlocation / ã®ä¸ã«å
¥ããªãã¨ãããã?
server { listen 80; server_name dev.example.net; access_log /var/log/nginx/dev.example.net.access.log main; error_log /var/log/nginx/dev.example.net.error.log; # location /foo/ { alias /home/gallu/test2/; set $debug_data "foo) $document_root $request_uri $uri"; } # location / { root /home/gallu/test/; set $debug_data "/) $document_root $request_uri $uri"; # location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; include fastcgi.conf; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; set $debug_data "/ php) $document_root $request_uri $uri $fastcgi_script_name"; } } # access_log /var/log/nginx/debug.log debug; }
[DEBUG][24/Feb/2023:18:18:01 +0900] / php) /home/gallu/test /t.php /t.php /t.php
åãããå½ããã£ã½ãã
ãããtest2ãåãããã«ã
server { listen 80; server_name dev.example.net; access_log /var/log/nginx/dev.example.net.access.log main; error_log /var/log/nginx/dev.example.net.error.log; # location /foo/ { alias /home/gallu/test2/; set $debug_data "foo) $document_root $request_uri $uri"; # location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; include fastcgi.conf; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; set $debug_data "foo php) $document_root $request_uri $uri $fastcgi_script_name"; } } # location / { root /home/gallu/test/; set $debug_data "/) $document_root $request_uri $uri"; # location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; include fastcgi.conf; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; set $debug_data "/ php) $document_root $request_uri $uri $fastcgi_script_name"; } } # access_log /var/log/nginx/debug.log debug; }
ãFile not found.ãããã?
[DEBUG][24/Feb/2023:18:19:48 +0900] foo php) /home/gallu/test2/ /foo/t.php /foo/t.php /foo/t.php
ãã
ããã ã¨ãSCRIPT_FILENAME ã« /home/gallu/test2//foo/t.php ã£ã¦å
¥ã£ã¦ããfooãéªéããªã
調ã¹ã㨠$request_filename ã£ã¦ã®ããããããã
http://nginx.org/en/docs/http/ngx_http_core_module.html
$request_filename
file path for the current request, based on the root or alias directives, and the request URI
使ããã?
server { listen 80; server_name dev.example.net; access_log /var/log/nginx/dev.example.net.access.log main; error_log /var/log/nginx/dev.example.net.error.log; # location /foo/ { alias /home/gallu/test2/; set $debug_data "foo) $document_root $request_uri $uri"; # location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; include fastcgi.conf; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; set $debug_data "foo php) $document_root $request_uri $uri $fastcgi_script_name $request_filename"; } } # location / { root /home/gallu/test/; set $debug_data "/) $document_root $request_uri $uri"; # location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; include fastcgi.conf; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; set $debug_data "/ php) $document_root $request_uri $uri $fastcgi_script_name"; } } # access_log /var/log/nginx/debug.log debug; }
[DEBUG][24/Feb/2023:18:22:21 +0900] foo php) /home/gallu/test2/ /foo/t.php /foo/t.php /foo/t.php /home/gallu/test2/t.php
ãããä¹ã£ãã
â¦â¦ã£ã¦ãã¨ã¯ã location / ã®ã»ãããã£ã¡ã§ãããã¢ãã?
server { listen 80; server_name dev.example.net; access_log /var/log/nginx/dev.example.net.access.log main; error_log /var/log/nginx/dev.example.net.error.log; # location /foo/ { alias /home/gallu/test2/; set $debug_data "foo) $document_root $request_uri $uri"; # location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; include fastcgi.conf; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; set $debug_data "foo php) $document_root $request_uri $uri $fastcgi_script_name $request_filename"; } } # location / { root /home/gallu/test/; set $debug_data "/) $document_root $request_uri $uri"; # location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; include fastcgi.conf; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; set $debug_data "/ php) $document_root $request_uri $uri $fastcgi_script_name $request_filename"; } } # access_log /var/log/nginx/debug.log debug; }
[DEBUG][24/Feb/2023:18:23:49 +0900] / php) /home/gallu/test /t.php /t.php /t.php /home/gallu/test/t.php
ããããããã
ããã¨ããããããã1ã¤ã®èµ·ç¹ã«ãããã
ãã¬ã¼ã ã¯ã¼ã¯ã§ã«ã¼ãã£ã³ã°ã¨ãããªãç³»ãªãã大ä½ããã§ããããã ã
â¦â¦ã¨ã¯ããä¸éçã«ã¯ããã¬ã¼ã ã¯ã¼ã¯? 使ããªãçç±ãªããã?ããããã®å¢ããå¤ãã®ã§ãããããããã«éçªã«è¸ã¿è¾¼ãã§ã¿ããã
æªç¥é¨åã¸ã®è¸ã¿è¾¼ã¿
try_files ã使ã£ãå é¨çãªç§»å
éµã«ãªãã®ã¯ try_files ã¨ããã¤ãã§ããã
http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files
Checks the existence of files in the specified order and uses the first found file for request processing; the processing is performed in the current context. The path to a file is constructed from the file parameter according to the root and alias directives. It is possible to check directoryâs existence by specifying a slash at the end of a name, e.g. â$uri/â. If none of the files were found, an internal redirect to the uri specified in the last parameter is made.
大éæã«ã¯ããã¡ã¤ã«ã®åå¨ããã£ãããã¡ã¦ãã£ã¦ããªãã£ããä¸çªæå¾ã®å¼æ°ã«å¾ããçãªæãã ã¨æããã¾ãã
ã¡ããã©test.htmlãããã®ã§ãããªãã£ããtest.htmlã«ãããã£ã¦æãã®ãæ¸ãã¦ã¿ã¾ãããã
ã»ã¼ã¾ã£ãããªæãããæ¹ãã¦æ¸ãã¦ã¿ã¾ãã
server { listen 80; server_name dev.example.net; access_log /var/log/nginx/dev.example.net.access.log main; error_log /var/log/nginx/dev.example.net.error.log; # root /home/gallu/test/; # try_files $uri $uri/ /test.html ; set $debug_data "/) $document_root $request_uri $uri $fastcgi_script_name $request_filename"; # access_log /var/log/nginx/debug.log debug; }
[DEBUG][24/Feb/2023:18:38:50 +0900] /) /home/gallu/test / /index.html /index.html /home/gallu/test/index.html
[DEBUG][24/Feb/2023:18:38:58 +0900] /) /home/gallu/test /test.html /test.html /test.html /home/gallu/test/test.html
[DEBUG][24/Feb/2023:18:39:14 +0900] /) /home/gallu/test /foo/ /test.html /test.html /home/gallu/test/test.html
[DEBUG][24/Feb/2023:18:39:58 +0900] /) /home/gallu/test /foo/hoge /test.html /test.html /home/gallu/test/test.html
ãããæå³éãã
è¦ãéãã§ã¯ãrequest_uriã¯å¤ããããuriã¨fastcgi_script_nameã¨request_filenameã¯æ¸ãæãããæããªãã ã
ãã¨ä¸å¿ãHTMLã®æç¹ã§ãURLã«ä»ãããã©ã¡ã¿ããããã確èªãã¦ãããã
å¤æ°çã«ã¯ä»¥ä¸ãããã½ãã
$is_args
â?â if a request line has arguments, or an empty string otherwise$args
arguments in the request line$query_string
same as $args
ãã£ã¨configã«æ¸ãã¦ãå¤ã確èªã
server { listen 80; server_name dev.example.net; access_log /var/log/nginx/dev.example.net.access.log main; error_log /var/log/nginx/dev.example.net.error.log; # root /home/gallu/test/; # try_files $uri $uri/ /test.html ; set $debug_data "/) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args is:$is_args (fin"; # access_log /var/log/nginx/debug.log debug; }
[DEBUG][24/Feb/2023:18:47:38 +0900] /) /home/gallu/test /index.html /index.html /index.html /home/gallu/test/index.html ar: is: (fin
[DEBUG][24/Feb/2023:18:47:47 +0900] /) /home/gallu/test /index.html?hoge=hoge /index.html /index.html /home/gallu/test/index.html ar:hoge=hoge is:? (fin
[DEBUG][24/Feb/2023:18:48:06 +0900] /) /home/gallu/test /index.html?hoge=hoge&foo=foo /index.html /index.html /home/gallu/test/index.html ar:hoge=hoge&foo=foo is:? (fin
[DEBUG][24/Feb/2023:18:48:27 +0900] /) /home/gallu/test /foo/hoge=hoge&foo=foo /test.html /test.html /home/gallu/test/test.html ar: is: (fin
ã»ããâ¦â¦ããtry_filesã§æ¸ãæãããããæå¾ã®ãã¤ããã©ã¡ã¿å¼ãç¶ãã§ãªãã®ãã
ã¿ãã¨ãis_argsã§?ã®æç¡ãargsã§(ãã£ãã)ãã©ã¡ã¿ãã£ã¦æãã ãªãã
ä¿®æ£ã
server { listen 80; server_name dev.example.net; access_log /var/log/nginx/dev.example.net.access.log main; error_log /var/log/nginx/dev.example.net.error.log; # root /home/gallu/test/; # try_files $uri $uri/ /test.html$is_args$args ; set $debug_data "/) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args is:$is_args (fin"; # access_log /var/log/nginx/debug.log debug; }
[DEBUG][24/Feb/2023:18:50:54 +0900] /) /home/gallu/test /foo/?hoge=hoge&foo=foo /test.html /test.html /home/gallu/test/test.html ar:hoge=hoge&foo=foo is:? (fin
try_files ã§PHPã絡ãã¦ã¿ã
ãã©ã¡ã¿ä»ãã§ã¡ããã¨åãããã¾ãã¯ãã£ããæãã¤ãã§ã
server { listen 80; server_name dev.example.net; access_log /var/log/nginx/dev.example.net.access.log main; error_log /var/log/nginx/dev.example.net.error.log; location / { root /home/gallu/test/; try_files $uri $uri/ /test.php$is_args$args ; set $debug_data "/) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args is:$is_args (fin"; # location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; include fastcgi.conf; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; set $debug_data "/ php) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args is:$is_args (fin"; } } # access_log /var/log/nginx/debug.log debug; }
[DEBUG][24/Feb/2023:18:56:02 +0900] / php) /home/gallu/test /foo/?hoge=hoge&foo=foo /test.php /test.php /home/gallu/test/test.php ar:hoge=hoge&foo=foo is:? (fin
ããåããã
ããâ¦â¦ãªãã¨ãªãããã£ã¦ã¯ãããªãã
&
PHPå´ã§ç¢ºèªãããã«ãã$_SERVER['REQUEST_URI']ãã§ã¡ããã¨ãå
ã
ã®callãã¦ããURL(ã¨ãã©ã¡ã¿)ãã¯ã¨ããã®ã§ã
å¤åããã¬ã¼ã ã¯ã¼ã¯å´ã®å¦çã¯ãããªã«åé¡ãªãããããªãããã? ã¨äºæ³ãã¦ã¿ãæãã
æªç¥ã®æ¬çª
ã«ã¼ãç´ä¸ã«Laravelãå ¥ãã¦ã¿ã
composer create-project laravel/laravel
ã§Laravelããã£ããinstallã
rootãå°ãæ¸ãæãã¦ãã¾ãã¯åããã¦ã¿ãã
server { listen 80; server_name dev.example.net; access_log /var/log/nginx/dev.example.net.access.log main; error_log /var/log/nginx/dev.example.net.error.log; location / { root /home/gallu/test/public/ ; try_files $uri $uri/ /index.php$is_args$args ; set $debug_data "/) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; # location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; include fastcgi.conf; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; set $debug_data "/ php) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; } } # access_log /var/log/nginx/debug.log debug; }
[DEBUG][24/Feb/2023:20:46:49 +0900] /) /home/gallu/test/public / / / /home/gallu/test/public/ ar:
ãã? 403ã«ãªãâ¦â¦ãã index å ¥ããªãã¨ã ããã
server { listen 80; server_name dev.example.net; access_log /var/log/nginx/dev.example.net.access.log main; error_log /var/log/nginx/dev.example.net.error.log; location / { root /home/gallu/test/public/ ; index index.php index.html; try_files $uri $uri/ /index.php$is_args$args ; set $debug_data "/) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; # location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; include fastcgi.conf; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; set $debug_data "/ php) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; } } # access_log /var/log/nginx/debug.log debug; }
[DEBUG][24/Feb/2023:20:48:46 +0900] / php) /home/gallu/test/public / /index.php /index.php /home/gallu/test/public/index.php ar:
ããOKã
(Laravelã®è¨å®ãªãããã£ã¦ãªãããã¨ã©ã¼åºã¦ããã©ãã®è¾ºã¯ç¯çå¤ãªã®ã§é¤å¤)
念ã®ããã«ãéã«
Route::get('/hoge', function () { return 'hoge'; });
ã®ã«ã¼ãã£ã³ã°ã追å ãã¦ç¢ºèªâ¦â¦æåOKã
ãµããã£ã¬ã¯ããªã«ãå¥ã®ãã¬ã¼ã ã¯ã¼ã¯ããã¶ã¡ããã§ã¿ã
ãã¦ã¡ã¤ã³ã®æ¬é¡ã®ã©çãä¸ã
ã¾ãã¯æºåã
ææã¡ã®Slim-Skeletonãå
¥ããã
composer create-project gallu/slim4-skeleton test2
ä»ã¾ã§ã®åæãè¾¼ãã¦ãã¾ãã¯ãã¿ã£ã¨æ¸ãã¦ã¿ããã
server { listen 80; server_name dev.example.net; access_log /var/log/nginx/dev.example.net.access.log main; error_log /var/log/nginx/dev.example.net.error.log; location /foo/ { alias /home/gallu/test2/public/ ; index index.php index.html; try_files $uri $uri/ /index.php$is_args$args ; set $debug_data "foo) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; # location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; include fastcgi.conf; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; set $debug_data "foo php) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; } } location / { root /home/gallu/test/public/ ; index index.php index.html; try_files $uri $uri/ /index.php$is_args$args ; set $debug_data "/) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; # location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; include fastcgi.conf; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; set $debug_data "/ php) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; } } # access_log /var/log/nginx/debug.log debug; }
ãã¨ãPHPå´ã§
$app->setBasePath('/foo');
ãæ¸ãã¦ãµããã£ã¬ã¯ããªãæå®ã
[DEBUG][24/Feb/2023:21:02:54 +0900] foo php) /home/gallu/test2/public/ /foo/ /foo/index.php /foo/index.php /home/gallu/test2/public/index.php ar:
ããOKã
â¦â¦ãã ãããããã©ã¡ã¿ã渡ãã¨
[DEBUG][24/Feb/2023:21:04:01 +0900] / php) /home/gallu/test/public /foo/sample /index.php /index.php /home/gallu/test/public/index.php ar:
ã£ã¦ãªããããå ã ã®è©±ã«æ»ã£ããlocation /foo/ ã«å ¥ã£ã¦ããã« location / ã«å ¥ã£ã¦ãã£ã¦ãã¾ã£ã¦ãããããDocumentRootããåãã¦æ¬²ããæã¨ã¯å¥ã«ããªãã
try_filesããå
ãä¸è¶³é£ã³ã«ãããããªãã
ã¡ãã£ã¨æ»ããã
location + try_files ãããã¡ãã£ã¨æ·±æããã
ãã£ããFWãå¤ãã¦ã¾ãhtmlã ãã®ã·ã³ãã«ãªç¶æ ã«ãã¦ãã¹ãã
server { listen 80; server_name dev.example.net; access_log /var/log/nginx/dev.example.net.access.log main; error_log /var/log/nginx/dev.example.net.error.log; location /foo/ { alias /home/gallu/test2/ ; index index.php index.html; set $debug_data "foo) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; } location / { root /home/gallu/test/ ; index index.php index.html; set $debug_data "/) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; } # access_log /var/log/nginx/debug.log debug; }
[DEBUG][24/Feb/2023:21:13:34 +0900] /) /home/gallu/test / /index.html /index.html /home/gallu/test/index.html ar:
[DEBUG][24/Feb/2023:21:13:36 +0900] foo) /home/gallu/test2/ /foo/ /foo/index.html /foo/index.html /home/gallu/test2/index.html ar:
ããåãã¦ãã
ãããããã®ã¾ã¾ãã¾ã㯠/ ã®ã»ãã ã try_files ã追å ãã¦åããã¦ã¿ããã
server { listen 80; server_name dev.example.net; access_log /var/log/nginx/dev.example.net.access.log main; error_log /var/log/nginx/dev.example.net.error.log; location /foo/ { alias /home/gallu/test2/ ; index index.php index.html; set $debug_data "foo) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; } location / { root /home/gallu/test/ ; index index.php index.html; try_files $uri $uri/ /test.html ; set $debug_data "/) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; } # access_log /var/log/nginx/debug.log debug; }
[DEBUG][24/Feb/2023:21:15:46 +0900] /) /home/gallu/test / /index.html /index.html /home/gallu/test/index.html ar:
[DEBUG][24/Feb/2023:21:15:53 +0900] /) /home/gallu/test /test.html /test.html /test.html /home/gallu/test/test.html ar:
[DEBUG][24/Feb/2023:21:15:58 +0900] /) /home/gallu/test /hogera /test.html /test.html /home/gallu/test/test.html ar:
ãããããã¾ã§ã¯æ³å®éãã
ãã¦â¦â¦fooã«ãåãããã«é©ç¨ãã¦ã¿ãããå¤åããããéµã
server { listen 80; server_name dev.example.net; access_log /var/log/nginx/dev.example.net.access.log main; error_log /var/log/nginx/dev.example.net.error.log; location /foo/ { alias /home/gallu/test2/ ; index index.php index.html; try_files $uri $uri/ /test.html ; set $debug_data "foo) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; } location / { root /home/gallu/test/ ; index index.php index.html; try_files $uri $uri/ /test.html ; set $debug_data "/) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; } # access_log /var/log/nginx/debug.log debug; }
[DEBUG][24/Feb/2023:21:17:26 +0900] foo) /home/gallu/test2/ /foo/ /foo/index.html /foo/index.html /home/gallu/test2/index.html ar:
[DEBUG][24/Feb/2023:21:17:31 +0900] foo) /home/gallu/test2/ /foo/test.html /foo/test.html /foo/test.html /home/gallu/test2/test.html ar:
[DEBUG][24/Feb/2023:21:17:38 +0900] /) /home/gallu/test /foo/hogera /test.html /test.html /home/gallu/test/test.html ar:
ãããããã ã
/foo/hogera ã®ã¢ã¯ã»ã¹ã®æã«ã location /foo/ ã«å
¥ããã« location / ã«å
¥ã£ã¦ããã ããããå
å¶ã
â¦â¦ããéãã/foo/ ã®ä¸ã®try_filesã®æ¸ãæ¹ã?
server { listen 80; server_name dev.example.net; access_log /var/log/nginx/dev.example.net.access.log main; error_log /var/log/nginx/dev.example.net.error.log; location ^~ /foo/ { alias /home/gallu/test2/ ; index index.php index.html; try_files $uri $uri/ /foo/test.html ; set $debug_data "foo) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; } location / { root /home/gallu/test/ ; index index.php index.html; try_files $uri $uri/ /test.html ; set $debug_data "/) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; } # access_log /var/log/nginx/debug.log debug; }
[DEBUG][24/Feb/2023:21:24:04 +0900] foo) /home/gallu/test2/ /foo/hogera /foo/test.html /foo/test.html /home/gallu/test2/test.html ar:
[DEBUG][24/Feb/2023:21:24:06 +0900] foo) /home/gallu/test2/ /foo/ /foo/index.html /foo/index.html /home/gallu/test2/index.html ar:
[DEBUG][24/Feb/2023:21:24:10 +0900] foo) /home/gallu/test2/ /foo/test.html /foo/test.html /foo/test.html /home/gallu/test2/test.html ar:
ãã!!
念ã®ããã
[DEBUG][24/Feb/2023:21:24:28 +0900] /) /home/gallu/test / /index.html /index.html /home/gallu/test/index.html ar:
[DEBUG][24/Feb/2023:21:24:37 +0900] /) /home/gallu/test /test.html /test.html /test.html /home/gallu/test/test.html ar:
[DEBUG][24/Feb/2023:21:24:42 +0900] /) /home/gallu/test /hogera /test.html /test.html /home/gallu/test/test.html ar:
ãããã
æ¹ãã¦ãã¬ã¼ã ã¯ã¼ã¯ã§ç¢ºèª
server { listen 80; server_name dev.example.net; access_log /var/log/nginx/dev.example.net.access.log main; error_log /var/log/nginx/dev.example.net.error.log; location /foo/ { alias /home/gallu/test2/public/ ; index index.php index.html; try_files $uri $uri/ /foo/index.php$is_args$args ; set $debug_data "foo) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; # location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; include fastcgi.conf; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; set $debug_data "foo php) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; } } location / { root /home/gallu/test/public/ ; index index.php index.html; try_files $uri $uri/ /index.php$is_args$args ; set $debug_data "/) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; # location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; include fastcgi.conf; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; set $debug_data "/ php) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; } } # access_log /var/log/nginx/debug.log debug; }
[DEBUG][24/Feb/2023:21:26:38 +0900] / php) /home/gallu/test/public / /index.php /index.php /home/gallu/test/public/index.php ar:
[DEBUG][24/Feb/2023:21:27:01 +0900] / php) /home/gallu/test/public /hoge /index.php /index.php /home/gallu/test/public/index.php ar:
[DEBUG][24/Feb/2023:21:27:09 +0900] foo php) /home/gallu/test2/public/ /foo/ /foo/index.php /foo/index.php /home/gallu/test2/public/index.php ar:
[DEBUG][24/Feb/2023:21:27:14 +0900] foo) /home/gallu/test2/public/ /foo/sample /foo/sample /foo/sample /home/gallu/test2/public/sample ar:
ãµããã£ã¬ã¯ããªå´ãã¨ããããlocationã¯ã¡ããã¨å ¥ã£ãã®ã§ãããã¡ããã ãªãã
[DEBUG][24/Feb/2023:21:29:03 +0900] foo) /home/gallu/test2/public/ /foo/css/dummy /foo/css/dummy /foo/css/dummy /home/gallu/test2/public/css/dummy ar:
ãããåå¨ãã¦ãããã¡ã¤ã«ã«å¯¾ãã¦ã¯åé¡ãªãåããã ã
ãªã®ã§ãåå¨ãã¦ããªããã¡ã¤ã«ã®æã«try_filesãé©ç¨ããã¦ãrequest_filename ã index.phpã«ãªããã¨ããããæ
ä¿ã§ããã°ããæãã ãªãã
ãªãã ãâ¦â¦ã¨ãããããä¸æããã£ã¦ãããã¿ã¼ã³ã§æ¸ãæãã¦ã¿ããã
location /foo/ { alias /home/gallu/test2/public/ ; index index.php index.html; #try_files $uri $uri/ /foo/index.php$is_args$args ; try_files $uri $uri/ /foo/test.html ; set $debug_data "foo) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; # location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; include fastcgi.conf; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; set $debug_data "foo php) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; } }
[DEBUG][24/Feb/2023:21:37:26 +0900] foo) /home/gallu/test2/public/ /foo/aaa /foo/test.html /foo/test.html /home/gallu/test2/public/test.html ar:
ãã¾ããããããâ¦â¦ãªãã???
ã¡ãã£ã¨ãã¤é²ãã¦ãããã
ã¨ãããããtest.phpãã¨ãã£ã¦ãã£ããã©ããªãã®ãããã?
location /foo/ { alias /home/gallu/test2/public/ ; index index.php index.html; #try_files $uri $uri/ /foo/index.php$is_args$args ; #try_files $uri $uri/ /foo/test.html ; try_files $uri $uri/ /foo/test.php ; set $debug_data "foo) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; # location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; include fastcgi.conf; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; set $debug_data "foo php) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; } }
[DEBUG][24/Feb/2023:21:40:08 +0900] foo php) /home/gallu/test2/public/ /foo/aaa /foo/test.php /foo/test.php /home/gallu/test2/public/test.php ar:
ãããããâ¦â¦æ¬¡ã
location /foo/ { alias /home/gallu/test2/public/ ; index index.php index.html; #try_files $uri $uri/ /foo/index.php$is_args$args ; #try_files $uri $uri/ /foo/test.html ; #try_files $uri $uri/ /foo/test.php ; try_files $uri $uri/ /foo/index.php ; set $debug_data "foo) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; # location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; include fastcgi.conf; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; set $debug_data "foo php) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; } }
[DEBUG][24/Feb/2023:21:41:52 +0900] foo php) /home/gallu/test2/public/ /foo/aaa /foo/index.php /foo/index.php /home/gallu/test2/public/index.php ar:
ãã? åã?
â¦â¦æ»ãã¦ã¿ããã
location /foo/ { alias /home/gallu/test2/public/ ; index index.php index.html; #try_files $uri $uri/ /foo/index.php$is_args$args ; #try_files $uri $uri/ /foo/test.html ; try_files $uri $uri/ /foo/test.php ; #try_files $uri $uri/ /foo/index.php ; set $debug_data "foo) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; # location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; include fastcgi.conf; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; set $debug_data "foo php) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; } }
[DEBUG][24/Feb/2023:21:45:42 +0900] foo) /home/gallu/test2/public/ /foo/sample /foo/sample /foo/sample /home/gallu/test2/public/sample ar:
ããæ»ã£ãâ¦â¦$is_args$args ãæªããã¦ã? ãã©ã¡ã¿ãªãã®ã«â¦â¦ãããä»ããªãã¨ãã©ã¡ã¿æ¸¡ããªããããªã???
試ãã¦ã¿ããã
location /foo/ { alias /home/gallu/test2/public/ ; index index.php index.html; #try_files $uri $uri/ /foo/index.php$is_args$args ; #try_files $uri $uri/ /foo/test.html ; try_files $uri $uri/ /foo/test.php ; #try_files $uri $uri/ /foo/index.php ; set $debug_data "foo) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; # location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; include fastcgi.conf; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; set $debug_data "foo php) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; } }
çµæâ¦â¦ãã$_SERVER['REQUEST_URI']ã«ã¯å ¥ã£ã¦ããã ãã©ã$_GETã«ã¯å ¥ã£ã¦ãããªãããâ¦â¦å¿µã®ãã追試ã
location /foo/ { alias /home/gallu/test2/public/ ; index index.php index.html; #try_files $uri $uri/ /foo/index.php$is_args$args ; #try_files $uri $uri/ /foo/test.html ; #try_files $uri $uri/ /foo/test.php ; try_files $uri $uri/ /foo/test.php$is_args$args ; #try_files $uri $uri/ /foo/index.php ; set $debug_data "foo) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; # location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; include fastcgi.conf; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; set $debug_data "foo php) $document_root $request_uri $uri $fastcgi_script_name $request_filename ar:$args"; } } >|| [DEBUG][24/Feb/2023:21:50:50 +0900] foo) /home/gallu/test2/public/ /foo/aaa?a=b&c=d /foo/aaa /foo/aaa /home/gallu/test2/public/aaa ar:a=b&c=d
ãããé§ç®ã orz
ãããã¡ããããªãã ããããã§ç
®è©°ã¾ã£ããªãâ¦â¦ã¡ãã£ã¨æ¾ç½®ã
å¾ã§è¦ç´ããããªããæ°ã¥ããããããªãã誰ããçªã£è¾¼ãã§ããããããããªãã®ã§ããã£ãããå¯ãããã orz