Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
    
still didn't find a way to fix this :( –  gryzzly Apr 20 '10 at 21:59
add comment

1 Answer

up vote 8 down vote accepted

You must not escape the period (.) in the second part of the rewrite:

rewrite ^/example3\.com/(.*)$ /example3\.com/index.php?id=$1 last;

should be

rewrite ^/example3\.com/(.*)$ /example3.com/index.php?id=$1 last;

But what does your id look like? If it's a number, you could try this out:

location /example3.com/ {
    index  index.php;
    rewrite "^/example3\.com/([0-9]+)$" /example3.com/index.php?id=$1 break;
}
share|improve this answer
    
thank you, that worked :-) –  gryzzly May 24 '10 at 23:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.