Welcome! Log In Create A New Profile

Advanced

Re: fastcgi, try_files, problems

Maxim Dounin
July 16, 2009 01:58PM
Hello!

On Thu, Jul 16, 2009 at 03:07:29PM +0200, Tomasz Pajor wrote:

> Maxim Dounin wrote:
>> Hello!
>>
>> On Thu, Jul 16, 2009 at 02:06:34PM +0200, Tomasz Pajor wrote:
>>
>>
>>> Hello all,
>>>
>>> I have a problem with proper configuration of my page.
>>>
>>> What I want to achieve is that:
>>> - http://domain.com/ should point to an upstream bucket of fastcgi apps.
>>> - http://domain.com/administrator should be served by a fastcgi
>>> server on the same machine as balancer, so it should point to
>>> 127.0.0.1:3000 in this case
>>> - i think there is a way to simplify the two backend.php entries
>>> - all /js/ entries for domain.com should be served staticly
>>> - static.domain.com should be served staticly
>>>
>>> Don't know what am I doing wrong, but the debug says that when i go
>>> to http://domain.com/administrator it uses the location
>>> /administrator but then it's redirected to /index.php and it uses
>>> location /, so not as I intended.
>>>
>>> Can You guys help me sort this out?
>>>
>>> Configuration is as follows:
>>>
>>> upstream apps {
>>> server 10.0.1.50:3000;
>>> }
>>>
>>> server {
>>> listen 80;
>>> server_name domain.com;
>>> error_log /var/log/nginx/domain-error.log debug;
>>>
>>> location / {
>>> root /disk0/vhosts/domain/public;
>>> try_files $uri $uri /index.php;
>>>
>>
>> See no reasons to test $uri twice.
>>
>>
>>> fastcgi_pass apps;
>>> #fastcgi_index index.php;
>>> fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
>>> include fastcgi_params;
>>> }
>>>
>>> location /administrator {
>>> root /disk0/vhosts/domain/public;
>>> try_files $uri $uri index.php;
>>>
>>
>> You fallback to 'index.php' which is wrong as far as I see (it
>> produces redirect to 'index.php' in case of no file found - it's
>> simply invalid since has no leading '/'). Probably you mean to use
>>
>> try_files $uri /administrator/index.php;
>>
>> instead, and probably it's a good idea to specify separate location for
>> /administrator/index.php to avoid internal redirection loop in case
>> there will be no /administrator/index.php file.
>>
> There is no /administrator/index.php file.
> I want to simply separate the administrator backend, and serve it from
> the same machine as balancer, because i've got all the gallery photos on
> this machine.

So there is no /disk0/vhosts/domain/public/administrator directory
at all, am I right?

> I'm migrating this from apache.
>
> .htaccess says:
> RewriteEngine On
> RewriteCond %{REQUEST_FILENAME} -s [OR]
> RewriteCond %{REQUEST_FILENAME} -l [OR]
> RewriteCond %{REQUEST_FILENAME} -d
> RewriteRule ^.*$ - [NC,L]
> RewriteRule ^.*$ index.php [NC,L]

As far as I understand you basically need to pass everything to
fastcgi while rewriting everything that doesn't exist to
index.php? Try something like this:

root /disk0/vhosts/domain/public;

fastcgi_index index.php;

location / {
try_files $uri $uri/ @fallback;
fastcgi_pass apps;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
...
}

location @fallback {
fastcgi_pass apps;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
...
}

location /administrator/ {
rewrite ^/administrator(.*) $1 break;
try_files $uri $uri/ @adminfallback;
fastcgi_pass 127.0.0.1:3000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
...
}

location @adminfallback {
fastcgi_pass 127.0.0.1:3000;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
...
}

>>> fastcgi_pass 127.0.0.1:3000;
>>> #fastcgi_index index.php;
>>> #fastcgi_param SCRIPT_FILENAME
>>> /disk0/vhosts/domain/public/index.php;
>>> fastcgi_param SCRIPT_FILENAME
>>> /disk0/vhosts/domain/public/$fastcgi_script_name;
>>> include fastcgi_params;
>>> }
>>>
>>> location /js/lib/xinha/plugins/ExtendedFileManager/backend.php {
>>> fastcgi_pass 127.0.0.1:3000;
>>> fastcgi_index backend.php;
>>> fastcgi_param SCRIPT_FILENAME
>>> /disk0/vhosts/domain/public/js/lib/xinha/plugins/ExtendedFileManager/backend.php;
>>> include fastcgi_params;
>>> access_log /var/log/nginx/backend1.log;
>>> }
>>>
>>> location /js/lib/xinha/plugins/ImageManager/backend.php {
>>> fastcgi_pass 127.0.0.1:3000;
>>> fastcgi_index backend.php;
>>> fastcgi_param SCRIPT_FILENAME
>>> /disk0/vhosts/domain/public/js/lib/xinha/plugins/ImageManager/backend.php;
>>> include fastcgi_params;
>>> access_log /var/log/nginx/backend2.log;
>>> }
>>>
>>> location ~ ^/(js)/ {
>>>
>>
>> Any reasons to use regex here? It should be enough to use normal
>>
>> location /js/ {
>>
>> unless you want to render the above '/js/.../backend.php' locations
>> useless.
>>
> Yes the regex is useless in this case.
> Is there any way of merging this to */backend.php locations?

Do not understand question. All 3 locations mentioned are quite
different in your config - /js/ serves static, while backend.php's
are passed to fastcgi (and one backend.php writes backend1.log,
while other - backend2.log). What do you mean by "merging"?

If you want to avoid duplicate parts of configuration - use
include directive or inheritance from upper levels.

Maxim Dounin
Subject Author Posted

fastcgi, try_files, problems

Tomasz Pajor July 16, 2009 08:06AM

Re: fastcgi, try_files, problems

Maxim Dounin July 16, 2009 08:41AM

Re: fastcgi, try_files, problems

Tomasz Pajor July 16, 2009 09:07AM

Re: fastcgi, try_files, problems

Maxim Dounin July 16, 2009 01:58PM

Re: fastcgi, try_files, problems

Tomasz Pajor July 17, 2009 05:35AM

Resuming http request processing

Marcus Clyne July 17, 2009 07:17PM

Re: Resuming http request processing

bbm September 05, 2009 08:33AM

Re: fastcgi, try_files, problems

mike July 16, 2009 12:42PM

Re: fastcgi, try_files, problems

Dick Middleton July 16, 2009 08:48AM

Re: fastcgi, try_files, problems

Maxim Dounin July 16, 2009 09:18AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 136
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready