Welcome! Log In Create A New Profile

Advanced

Serving PHP files from many different locations

Posted by TPJ 
TPJ
Serving PHP files from many different locations
August 09, 2010 05:55AM
I'd like to have one virtual server handling many different locations. So, I started with a following basic config:

[code]
server {
listen 80 default;
server_name my.server.name;

location / {
root /my/root/location;
index index.html index.htm;
}

location ~ \.php$ {
fastcgi_pass 127.0.0.1:MYPORT;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /my/root/location$fastcgi_script_name;
include fastcgi_params;
}
}
[/code]


Everything worked as it should.

So I decided to add my first, additional location:

[code]
location ^~ /my_first_loc {
alias /my/first/loc/;
}
[/code]


And all the html files were served properly.

My problems began when I was trying to get PHP files located in my first location to work properly. I added the following location:

[code]
location ~ /my_first_loc/.*\.php$ {
fastcgi_pass 127.0.0.1:MYPORT;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /my/first/loc$fastcgi_script_name;
include fastcgi_params;
}
[/code]


but all I got was the bare .php file - it was served by Nginx, instead of being sent to PHP interpreter.

What did I do wrong? Is it my config that is wrong, or is it my approach to solve my problem (should I do it in a different way)? (And my problem is: how to properly serve PHP files from many different locations?)
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 298
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