How can I reproduce this behavior:
with a request to /foo/bar
try file: foo/bar
try index.htm: foo/bar/
try file: foo/bar.htm
try file: foo/bar.html
try parse php: foo/bar.php
try file: /layout.htm
try file: /layout.html
try parse php: /layout.php
return 404 if not found.
I try this:
location / {
try_files $uri $uri/ $uri.htm $uri.html $uri.php layout.htm
/layout.html /layout.php;
}
Everything works, except PHP that returns as text file showing the
source code.
ps: Is there a blog post that explain exactly how location, if,
rewrite and try_files works?
The docs are not so clear about how the flow works.
Marcos N.
sounds like you just need a php location? this works like a charm.
server {
listen 80;
server_name foo.com;
index index.php index.html;
root /home/foo/web/foo.com;
include /etc/nginx/defaults.conf;
include /etc/nginx/expires.conf;
try_files $uri $uri/ /wordpress/index.php?q=$uri;
location ~ .php$ {
fastcgi_pass 127.0.0.1:11000;
include /etc/nginx/fastcgi.conf;
}
}
Sorry, I forget to say that php is working.
I create a file named phpinfo.php
if I access /phpinfo.php works like always before,
but if I try /phpinfo it shows the source code.
Marcos N.
+55 44 9918-8488
On Fri, May 28, 2010 at 1:35 AM, Marcos N. [email protected]
wrote:
Sorry, I forget to say that php is working.
I create a file named phpinfo.php
if I access /phpinfo.php works like always before,
but if I try /phpinfo it shows the source code.
because except for the last one in the try_files, everything are
processed within the location block (ie no location search).
–
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
On Thu, May 27, 2010 at 11:13 AM, Marcos N. [email protected]
wrote:
try file: /layout.html
Everything works, except PHP that returns as text file showing the source code.
nginx Info Page
As someone else mentioned it serves the file because that is what you
asked it to do. You will probably need something more convoluted
along the following lines, but I don’t guarantee it is correct (to
whit, I don’t think the try_files in @second is correct but I copied
your line):
upstream backend {
server 127.0.0.1:9000;
}
server {
listen 80;
server_name supercomplicatedphpcrap;
root /path/to/root;
location / {
try_files $uri $uri/ $uri.htm $uri.html @first;
}
location @first {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $uri.php
fastcgi_pass backend;
fastcgi_intercept_errors on;
error_page 404 =@second;
}
location @second {
try_files layout.htm /layout.html /layout.php;
}
}
– Merlin
probably because it’s try_files’ing the uri and putting on .php
internally but NOT actually considering it originally a .php file? i
think.
On Thu, May 27, 2010 at 03:13:32PM -0300, Marcos N. wrote:
try file: /layout.html
Everything works, except PHP that returns as text file showing the source code.
ps: Is there a blog post that explain exactly how location, if,
rewrite and try_files works?
The docs are not so clear about how the flow works.
You can not mix different handlers: static and php, in one try_files.
My variant is similar to Merlin’s:
location / {
try_files $uri $uri/index.htm $uri.htm $uri.html @php;
}
location @php1 {
try_files $uri.php @file1;
fastcgi_pass ...
}
location @file1 {
try_files /layout.htm /layout.html @php2;
}
location @php2 {
try_files /layout.php =404;
fastcgi_pass ...
}
–
Igor S.
http://sysoev.ru/en/
How about this one?
try_files $uri $uri/ $uri.htm $uri.html @php;
location @php {
rewrite ^.*$ $uri.php;
}
Do I need to put try files inside a location / { } ?
Is a good idea use: if (-f $uri.php) {do php handler}
Marcos N.
+55 44 9918-8488
On Thu, May 27, 2010 at 4:04 PM, Igor S. [email protected] wrote:
try parse php: foo/bar.php
}
location / {
try_files $uri $uri/index.htm $uri.htm $uri.html @php;
}
location @php1 {
try_files $uri.php @file1;
the follow lines are always executed or only when the try_file above
match $uri.php ?
fastcgi_pass ...
}
location @file1 {
try_files /layout.htm /layout.html @php2;
}
location @php2 {
What the =404 below means?
On Thu, May 27, 2010 at 04:14:38PM -0300, Marcos N. wrote:
How about this one?
try_files $uri $uri/ $uri.htm $uri.html @php;
location @php {
rewrite ^.*$ $uri.php;
}
You do not test laytout files here.
Here is the right configuration:
š š location / {
š š š š try_files š$uri $uri/index.htm $uri.htm $uri.html @php;
š š }
š š location @php1 {
š š š š try_files š$uri.php š=404;
š š š š fastcgi_pass š…
š š }
Do I need to put try files inside a location / { } ?
You should put it in most specific location.
Is a good idea use: if (-f $uri.php) {do php handler}
No.
with a request to /foo/bar
rewrite and try_files works?
š š š š try_files š$uri.php š@file1;
the follow lines are always executed or only when the try_file above
match $uri.php ?
Yes.
š š š š fastcgi_pass š…
š š }
š š location @file1 {
š š š š try_files š/layout.htm /layout.html @php2;
š š }
š š location @php2 {
What the =404 below means?
return 404 code as the last resort.
š š š š try_files š/layout.php š=404;
š š š š fastcgi_pass š…
š š }
–
Igor S.
http://sysoev.ru/en/
If we ignore the layout files, using the rewrite solution is a good one?
Marcos N.
+55 44 9918-8488
2010/5/27 Igor S. [email protected]:
Thanks all for helping.
Marcos N.
+55 44 9918-8488
2010/5/27 Igor S. [email protected]:
On Thu, May 27, 2010 at 04:35:56PM -0300, Marcos N. wrote:
If we ignore the layout files, using the rewrite solution is a good one?
No. A good solution is:
š š location / {
š š š š try_files š$uri $uri/index.htm $uri.htm $uri.html @php;
š š }
š š location @php1 {
š š š š try_files š$uri.php š=404;
š š š š fastcgi_pass š…
š š }
–
Igor S.
http://sysoev.ru/en/