5

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: https://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.

  • still didn't find a way to fix this :( – Misha Reyzlin Apr 20 '10 at 21:59
10

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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