Nginx: Rewrite rule for subfolder
Posted
by gryzzly
on Server Fault
See other posts from Server Fault
or by gryzzly
Published on 2010-04-10T13:13:05Z
Indexed on
2010/04/10
13:23 UTC
Read the original article
Hit count: 1083
Hello, I have a subdomain where I want to keep projects I am working on, in order to show these projects to clients.
Here is the configuraion file from /etc/nginx/sites-available/projects:
server {
listen 80;
server_name projects.example.com;
access_log /var/log/nginx/projects.example.com.access.log;
error_log /var/log/nginx/projects.example.com.error.log;
location / {
root /var/www/projects;
index index.html index.htm index.php;
}
location /example2.com {
root /var/www/projects/example2.com;
auth_basic "Stealth mode";
auth_basic_user_file /var/www/projects/example2.com/htpasswd;
}
location /example3.com/ {
index index.php;
if (-f $request_filename) {
break;
}
if (!-f $request_filename) {
rewrite ^/example3\.com/(.*)$ /example3\.com/index.php?id=$1 last;
break;
}
}
location ~ \.php {
root /var/www/mprojects;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}
I want to be able to place different php engines (wordpress, getsimple etc.) in subfolders. These engines have different querry parameters (id, q, url etc.) so in order to make preety URLs work I have to make a rewrite. However, above doesn't work. This is the response I get:
Warning: Unknown: Filename cannot be empty in Unknown on line 0
Fatal error: Unknown: Failed opening required '' (include_path='.:/usr/local/lib/php') in Unknown on line 0
If I take out "location /example3.com/" rule, then everything works but with no preety URLs. Please help.
The configuration is based on this post: http://stackoverflow.com/questions/2119736/cakephp-in-a-subdirectory-using-nginx-rewrite-rules
I am using Ubuntu 9.10 and nginx/0.7.62 with php-fpm.
© Server Fault or respective owner