Forum: NGINX Global PHP Rule

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Mathew D. (Guest)
on 2009-05-04 04:13
(Received via mailing list)
Hi,
Is there a way to specify a global PHP location rule? As you can see
below,
the PHP block is repeated which is no good.

# domain1.tld
server
{
server_name domain1.tld;
root html/domain1;

location ~ \.php$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

# domain2.tld
server
{
server_name domain2.tld;
root html/domain2;

location ~ \.php$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Thank You.
Michael S. (Guest)
on 2009-05-04 04:49
(Received via mailing list)
On Sun, May 3, 2009 at 5:06 PM, Mathew D.
<removed_email_address@domain.invalid> wrote:

> location ~ \.php$
> {
> fastcgi_pass 127.0.0.1:9000;
> fastcgi_index index.php;
> fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
> include fastcgi_params;
> }
> }

You can put these in fastcgi_params:

fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

Also you can put all the fastcgi_params globally on the http {} block.

I have done that, and it works well, there is some random situation
though where if I try to override a fastcgi_param somewhere else, all
of them get unset.
Jim O. (Guest)
on 2009-05-04 04:50
(Received via mailing list)
Mathew D. wrote:
> Hi,
>
> Is there a way to specify a global PHP location rule? As you can see
> below, the PHP block is repeated which is no good.

Best as I can tell from
http://wiki.nginx.org/NginxHttpFcgiModule#fastcgi_pass, that's they way
it is.

    fastcgi_pass

    syntax: fastcgi_pass fastcgi-server

    default: none

    context: location, if in location

    Directive assigns the port or socket on which the FastCGI-server is
    listening. Port can be indicated by itself or as an address and
    port, for example:

      fastcgi_pass   localhost:9000;

    using a Unix domain socket:

      fastcgi_pass   unix:/tmp/fastcgi.socket;

> fastcgi_index index.php;
>
> location ~ \.php$
> {
> fastcgi_pass 127.0.0.1:9000 <http://127.0.0.1:9000>;
> fastcgi_index index.php;
> fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
> include fastcgi_params;
> }
> }
>
> Thank You.

Jim
Jim O. (Guest)
on 2009-05-04 05:04
(Received via mailing list)
Michael S. wrote:
>> }
> I have done that, and it works well, there is some random situation
> though where if I try to override a fastcgi_param somewhere else, all
> of them get unset.
>
>
Correct me if I'm wrong, but you still have to put

location ~ \.php$ {
  fastcgi_pass 127.0.0.1:9000;

  ...
}

for each server block where you want to configure php. Even if you are
able to put the fastcgi_pass directive into fastcgi_params, something I
haven't tried, you'd still need

location ~ \.php$ {

  include fastcgi_params;
}

in any server block where you wanted to run run php scripts since
fastcgi_pass has to be in a location block.


Jim
Mathew D. (Guest)
on 2009-05-04 05:12
(Received via mailing list)
I guess I'll live with it for now.

The idea was to not repeat this data so it'd be easier to setup PHP on a
variety of domains without repetition. Maybe Igor can look at this as a
new
feature request.

Thank You.

2009/5/4 Jim O. <removed_email_address@domain.invalid>
Edho P Arief (Guest)
on 2009-05-04 05:35
(Received via mailing list)
On Mon, May 4, 2009 at 8:05 AM, Mathew D.
<removed_email_address@domain.invalid> wrote:
> I guess I'll live with it for now.
> The idea was to not repeat this data so it'd be easier to setup PHP on a
> variety of domains without repetition. Maybe Igor can look at this as a new
> feature request.
> Thank You.

you can also put the whole location block in a file then include it on
every vhost
Michael S. (Guest)
on 2009-05-04 05:42
(Received via mailing list)
On Sun, May 3, 2009 at 5:56 PM, Jim O. <removed_email_address@domain.invalid>
wrote:

> tried, you'd still need
yup. that's the only piece that i need to specifically put.
This topic is locked and can not be replied to.