Nginx 1.7.0: location @php

TECK nginx-forum at nginx.us
Mon Jun 2 03:47:33 UTC 2014


Francis,

We are going in circles without reaching a solution. I think what I asked is
very clear and simple:
How do I avoid repeating a segment of configuration code assigned to @php
into various locations:
location @php {
	try_files $uri =404;
	fastcgi_split_path_info ^(.+\.php)(/.+)$;
	fastcgi_pass fastcgi;
	fastcgi_param PATH_INFO $fastcgi_path_info;
	fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;
	include fastcgi.conf;
}

The above configuration will never change, regardless in what location is
used:
location ^~ /alpha {
	auth_basic "Restricted Access";
	auth_basic_user_file htpasswd;
	try_files $uri $uri/ /alpha/index.php?$uri&$args;
	location ~ \.php$ {
		try_files @php =404;
	}
}

location ^~ /beta {
	try_files $uri $uri/ /beta/index.php?$uri&$args;
	location ~ \.php$ {
		try_files @php =404;
	}
}

If I replace the @php contents into /beta location, everything works.
location ^~ /beta {
	try_files $uri $uri/ /beta/index.php?$uri&$args;
	location ~ \.php$ {
		try_files $uri =404;
		fastcgi_split_path_info ^(.+\.php)(/.+)$;
		fastcgi_pass fastcgi;
		fastcgi_param PATH_INFO $fastcgi_path_info;
		fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;
		include fastcgi.conf;
	}
}

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,250342,250548#msg-250548



More information about the nginx mailing list