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.
7b660a44f60a7ba9bb6e12d817f4b038?d=identicon&s=25 Mathew Davies (Guest)
on 2009-05-04 02: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.
F5a6ed477b109fe6acc11a5a8f87e7e8?d=identicon&s=25 Michael Shadle (Guest)
on 2009-05-04 02:49
(Received via mailing list)
On Sun, May 3, 2009 at 5:06 PM, Mathew Davies
<thepixeldeveloper@googlemail.com> 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.
2c6f80fff253635f12c249ef4f116796?d=identicon&s=25 Jim Ohlstein (Guest)
on 2009-05-04 02:50
(Received via mailing list)
Mathew Davies 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
2c6f80fff253635f12c249ef4f116796?d=identicon&s=25 Jim Ohlstein (Guest)
on 2009-05-04 03:04
(Received via mailing list)
Michael Shadle 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
7b660a44f60a7ba9bb6e12d817f4b038?d=identicon&s=25 Mathew Davies (Guest)
on 2009-05-04 03: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 Ohlstein <jim.ohlstein@gmail.com>
96dfd0f0a8399d3b03feba1e6a562e0a?d=identicon&s=25 Edho P Arief (Guest)
on 2009-05-04 03:35
(Received via mailing list)
On Mon, May 4, 2009 at 8:05 AM, Mathew Davies
<thepixeldeveloper@googlemail.com> 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
F5a6ed477b109fe6acc11a5a8f87e7e8?d=identicon&s=25 Michael Shadle (Guest)
on 2009-05-04 03:42
(Received via mailing list)
On Sun, May 3, 2009 at 5:56 PM, Jim Ohlstein <jim.ohlstein@gmail.com>
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.