技术解析
不好意思,因为在公司写英文,所以以下问题是用英文写的。
Configuration 1:
server {
index index.html index.php
location / {
try_files $uri $uri/;
}
location ~ [^/]\.php(/|$) {
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
}
Configuration like the above (Configuration 1) will return 500 Internal Server Error when visiting ...domain.../20170223
, ...domain.../20170223/
but not ...domain.../20170223/index.php
.
So I am think try_files
is executed before index
and then cause a internal redirect loop thus 500 Server Internal Error because if index
runs first then .../20170223/
should works just fine while in fact is not.
But
Configuration 2:
server {
index index.html index.php
location / {
try_files $uri $uri/ =404;
}
location ~ [^/]\.php(/|$) {
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
}
works for all ...domain.../20170223
, ...domain.../20170223/
and ...domain.../20170223/index.php
.
Which leads me to think when try_files
is encountered with folder URI like .../20170223/
it makes an internal redirect. But contradiction is if try_files
runs before index
, it will be a redirect loop which is not true in this practice.
Then there is again not clue which one (try_files
or index
) runs first.
To exclude the position of index
directive problem, the following configuration 3 & 4 are tested with same result as Configuration 1.
Configuration 3:
server {
location / {
index index.html index.php
try_files $uri $uri/;
}
location ~ [^/]\.php(/|$) {
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
}
Configuration 4:
server {
location / {
try_files $uri $uri/;
index index.html index.php
}
location ~ [^/]\.php(/|$) {
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
}
And there comes my problem.
The Configuration 2 doesn't receive POST data from a submit when action is assigned with
...domain.../20170223
but works for ...domain.../20170223/
and ...domain.../20170223/index.php
.
So why???
Does internal redirect lost 国外服务器POST data? Does try_files
append index.php
to folder uri according to index
first and then make a redirect? In the different words for same meaning, does try_files
make redirect but index
never make redirect? Is index
a dictionary for try_files
whose default value is just try_files $uri =404;
(this assumption still didn't explain for Configuration 1 practice)?
No idea according to the following official documents:
with the summary:
index
processes requests ending with the slash character (‘/’), and note that using an index file causes an internal redirect, and the request can be processed in a different location (for instance, a “/” request may actually be processed in a second location as “/index.html ”.).try_files
has specified ordered file lists and uri
or =code
at last, if none of the files were found, then an internal redirect to the uri specified in the last parameter is made. (Notice: only the last part is internal redirect, the ones ahead are all served directly by Nginx as static files.)And is there any solve to have a clean post action url without tailing slash /
?