index or try_files in reverse proxy

Igor Sysoev is at rambler-co.ru
Thu Aug 13 11:22:38 MSD 2009


On Wed, Aug 12, 2009 at 03:27:47PM -0400, meto wrote:

> I'm trying to set a reverse proxy for some time now and i'm out of ideas...
> 
> 
> index index.html index.htm index.php;
> 	
> 		location / {
> 		try_files $uri @proxy_backend;
> 
> 		}
> 		
> 		location ~ ^(.+\.php)(.*)$ {

- 		location ~ ^(.+\.php)(.*)$ {
+ 		location ~ ^(.+\.php|/)$ {

If you want also to support PATH_INFO after PHP script, then you need
to split PATH_INFO:

    location ~ ^(.+\.php.*|/)$ {
        fastcgi_split_path_info         ^(.+\.php)(.*)$;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  PATH_INFO        $fastcgi_path_info;
        ...

> 		error_page 404 /errors_pages/404.html;
> 		
> 		fastcgi_pass	php;
> 		
> 		fastcgi_index  index.php;
> 		fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
> 		fastcgi_intercept_errors on;
> 		fastcgi_buffers 100 32k;
> 		fastcgi_read_timeout 600;
> 
> 		include fastcgi_params;
> 		}
> 			
> 		location @proxy_backend {
> 		
> 		proxy_pass http://IP:80;
> 
> 		access_log off;
> 		expires off;
> 		}
> 
> 
> Almost everything is fine, but it's not passing domain.com/ to index.php via FastCGI, but goes to proxy :/ other php files are parsed by "php" upstream in nginx including domain.com/index.php (when included in URI).
> 
> I also tried commenting index ... and using try_files $uri $uri/index.php, but then it provides index.php as text, ignoring fastcgi server. Am i doing something wrong, or is there a small bug?
> 
> Posted at Nginx Forum: http://forum.nginx.org/read.php?2,4893,4893#msg-4893
> 

-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list