Rewrite and FastCGI.

Thomas Martin tmartincpp at gmail.com
Tue Oct 9 14:50:32 UTC 2012


Hi Francis.

FYI I read the documentation before to send my first email but I
misunderstood the part about "^~" and also I didn’t clearly realized
that "One request is handled in one location".

So with your clarification I was able to make something working:
	# DocumentRoot
	root /www/;

	# dir1
	location /dir1 {
		rewrite ^(.*) https://$host$1 permanent;
	}
	# dir2
	location /dir2 {
		# php5-fpm
		location ~ \.(php|phtml)$ {
			fastcgi_param	PHP_VALUE "include_path=/www/dir2:/www/dir2/common/include:.";
			fastcgi_param	ENVIRONMENT_NAME devs;
			fastcgi_param	DB_CONF_DIRECTORY /etc/itf/db/devs/;

			include /etc/nginx/sites-conf.d/php-fpm;
		}
	}
    # All others
    location / {
		# php5-fpm
		location ~ \.(php|phtml)$ {
			fastcgi_param	ENVIRONMENT_NAME devs;
			fastcgi_param	DB_CONF_DIRECTORY /etc/db/devs/;
			
			include /etc/nginx/sites-conf.d/php-fpm;
		}
    }

It seems to work as expected; I guess I could use "^~" too but I
didn't tried yet.
At first I wanted to avoid repetition of the php-fpm's part but I
didn't realized that it wasn't doable.

Thanks for your help and again this is really appreciated!

Regards.

2012/10/9 Francis Daly <francis at daoine.org>:
> On Tue, Oct 09, 2012 at 02:03:40PM +0200, Thomas Martin wrote:
>
> Hi there,
>
>>         # dir1
>>         location /dir1 {
>>                 rewrite ^(.*) https://$host$1 permanent;
>>         }
>>
>>         # php5-fpm
>>         location ~ \.(php|phtml)$ {
>>                         include         /etc/nginx/fastcgi_params;
>>                         fastcgi_pass    unix:/var/run/php-fpm/php-fpm.sock;
>>                         fastcgi_param   SCRIPT_FILENAME
>> /www/$fastcgi_script_name;
>>                 }
>>         }
>
>> The rewrite is working great for a html page (for example) but not for
>> a php page.
>
> One request is handled in one location.
>
> You have
>
>     location /dir1 {}
>     location ~ \.(php|phtml)$ {}
>
> Possibly what you want is
>
>     location ^~ /dir1 {}
>     location ~ \.(php|phtml)$ {}
>
> or maybe
>
>     location /dir1 {}
>     location / {
>       location ~ \.(php|phtml)$ {}
>     }
>
> See http://nginx.org/r/location for details.
>
> (Possibly what you want is some other configuration: the important thing
> to keep in mind is: for this request, which one location do you wish to
> handle it? Then configure the locations accordingly.)
>
>         f
> --
> Francis Daly        francis at daoine.org
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx



More information about the nginx mailing list