Welcome! Log In Create A New Profile

Advanced

Rewrite and FastCGI.

Thomas Martin
October 09, 2012 08:04AM
Hello everyone!

I'm trying to use rewrite and fastcgis with Nginx 1.2.1 (from the
Debian Wheezy package).

My root directory looks like this:
/www/dir1
/www/dir2


In my server's file I have this:
root /www/;

# 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.
Same results with:
root /www/;

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;
}
}


I need to use php's fastcgi for dir1 and dir2 but only to redirect
dir1 in https. To be honest I try many settings but without any
results.
It seems that fastcgi (or upstream) have always the priority on location.

A solution could be to add a rewrite in the php's location too to have
something like this (but that seems rally ugly to me):
root /www/;

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;
}
}

# 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;
}
}


Any help would be really appreciated!

Thanks for reading anyway.

Regards.

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Rewrite and FastCGI.

Thomas Martin October 09, 2012 08:04AM

Re: Rewrite and FastCGI.

Francis Daly October 09, 2012 08:54AM

Re: Rewrite and FastCGI.

Thomas Martin October 09, 2012 10:52AM

Re: Rewrite and FastCGI.

Francis Daly October 10, 2012 08:38AM

Re: Rewrite and FastCGI.

Thomas Martin October 11, 2012 03:50AM

Re: Rewrite and FastCGI.

Andre Jaenisch October 11, 2012 07:14AM

Re: Rewrite and FastCGI.

Thomas Martin October 11, 2012 07:22AM

Re: Rewrite and FastCGI.

tysonlee October 10, 2012 05:32AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 162
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready