Welcome! Log In Create A New Profile

Advanced

Shared PHP app with SEF URLs.

Posted by mrkennie 
Shared PHP app with SEF URLs.
January 17, 2013 07:09PM
Hi, I am soon to set up a new server which is replacing an old one which is currently running apache. I've been dabbling with lighttpd but I really want to use Nginx because, well basically, it's cool!

Anyhow, I have a shared PHP app which will serve several different websites but I'm stuck (and perhaps slightly confused) with how I should actually approach this. Normally in Apache I would setup an alias and that's it. I'm currently taking the symlink approach which works fine for say phpmyadmin but my PHP app is slightly different where it uses a sort of similar method to Codeigniter. Basically the .htaccess rule is ^(.*)$ index.php?$1 [NC,L] so it ends up like index.php?foo/bar/.. and so on to PHP but accessed like http://foo.com/admin/foo/bar.

Problem I'm having right now is I can't get fastcgi_split_path_info to work and I end up with an empty PATH_INFO and SCRIPT_NAME. I know I'm doing something wrong but I just can't see it.

Here's my config anyway which is currently incomplete as I'm trying to build it up:
/mushin/admin is a symlink to the shared PHP app in /usr/share/

server {
listen 80;
server_name mrkennie.kicks-ass.net;

index index.php index.html index.htm;
root /home/customers/webs/kryogenic/mrkennie.kicks-ass.net/www/;

location ~ /mushin/admin/(.*)$ {
try_files $uri $uri/ /index.php?$1;
}

location ~ ^.+\.php {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}

I'm at the understanding that $fastcgi_path_info and $fastcgi_script_name should be set by fastcgi_split_path_info, assuming there is a match but they are both blank.

I'm using Nginx 1.2.1 and php5-fpm 5.4.6 on Ubuntu 12.10.

I hope this all makes sense, I'm not very good at trying to explain things. I've been trying to avoid the pitfalls that I've been reading on the wiki and trying to do everything the Nginx way. I know I'm doing something wrong but very keen to learn!



Edited 1 time(s). Last edit at 01/17/2013 07:10PM by mrkennie.
Shared PHP app with SEF URLs.
January 19, 2013 07:24AM
I fixed this particular problem by not using fastcgi_split_path_info and simply assigning PATH_INFO to $args and fixing the path to $document_root/mushin/admin as part of SCRIPT_FILENAME and PATH_TRANSLATED. I suspect there are other, possibly better ways but this seems to work just fine for me so far.



Edited 2 time(s). Last edit at 01/19/2013 07:31AM by mrkennie.
Re: Shared PHP app with SEF URLs.
January 19, 2013 12:55PM
The following seems to work and is able to run other scripts normally such as phpmyadmin etc. I can access /admin/foo/bar just fine but /admin/ just downloads index.php. I've cleared my browser cache in case that was causing it but this has me stumped. It's not matching any rules I have and I can't seem to find why. Does anyone have any ideas?

listen 80;
server_name mrkennie.kicks-ass.net;

index index.php index.html index.htm;
root /home/customers/webs/kryogenic/mrkennie.kicks-ass.net/mushin/;

location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
expires max;
log_not_found off;
}

location ^~ /admin/ {
try_files $uri $uri/ @mushin;
}

location / {
try_files $uri $uri/ /index.php;
}

location @mushin {
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/admin/index.php;
fastcgi_param PATH_TRANSLATED $document_root/admin/index.php;
}

location ~ \.php {
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
try_files $uri =404;
}
Re: Shared PHP app with SEF URLs.
January 19, 2013 06:40PM
Well, with a little perseverance I've managed to come up with the following which gets everything working. I removed $uri/ from try_files in the /admin location block and voila! I hope this helps someone anyway.

server {
listen 80;
server_name mrkennie.kicks-ass.net;

index index.php index.html index.htm;
root /home/customers/webs/kryogenic/mrkennie.kicks-ass.net/mushin/;

location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
expires max;
log_not_found off;
}

location ^~ /admin/ {
try_files $uri @mushin;
}

location / {
try_files $uri $uri/ /index.php;
}

location @mushin {
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/admin/index.php;
fastcgi_param PATH_TRANSLATED $document_root/admin/index.php;
}

location ~ \.php {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
try_files $uri =404;
}
}
Sorry, only registered users may post in this forum.

Click here to login

Online Users

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