I'm trying to make the subdomain work when accessing to dev.domain.com, it should tail to the /var/www/domain.com/www/dev where /var/www/domain.com/www/ is the root of domain.com. When I access to dev.domain.com it lands me to the root page of domain.com.

This is my configuration file for domain.com in sites-enabled:

server {

    server_name     *.domain.com domain.com;
    root            /var/www/domain.com/www;
    index           index.php index.htm index.html;
    error_page      404 /404.html;
    error_page      500 502 503 504  /50x.html;

    access_log      /var/www/domain.com/logs/access.log;
    error_log       /var/www/domain.com/logs/errors.log;

    # subdomain rewrites
    if ($host !~* ^www\.domain\.com$) {}
    if ($host ~* ^([^.]+)\.domain\.com$) {
        set $auto_subdomain $1;
    }
    if (-d /var/www//www/$auto_subdomain) {}
    if (-f /var/www//www/$auto_subdomain$uri) {
        rewrite ^(.*)$ /$auto_subdomain$uri;
        break;
    }

    # use fastcgi for all php files
    location ~ \.php$
    {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /var/www/domain.com/www$fastcgi_script_name;
        include fastcgi_params;
    }

    location /dev {
        auth_basic            "Development";
        auth_basic_user_file  /var/www/domain.com/www/dev/authfile;
    }
}

I also need it to be aware with www.domain.com that it should not look for the www directory in the root of /var/www/domain.com/www/.

link|improve this question

feedback

2 Answers

up vote 0 down vote accepted

Follow the procedure in the last few commands here:

http://www.idolbin.com/blog/server-management/vps-setup-guide/configure-domains-and-subdomains-in-your-vps-running-nginx/

You'll find some little changes in configuration to the following config is suggested:

http://www.idolbin.com/blog/server-management/vps-setup-guide/setup-nginx-web-server-not-apache-on-ubuntu-10-04/

link|improve this answer
feedback

According to nginx documentation, you are using an ineffective way with multiple if directives. So, you should define a separate server block for dev.example.com and use try_files instead.

link|improve this answer
How can I write this? – Burning the Codeigniter Oct 4 '11 at 16:46
Hello? I'm still asking about this. – Burning the Codeigniter Oct 4 '11 at 20:09
No? You're not gonna help? – Burning the Codeigniter Oct 5 '11 at 17:59
Both Nginx documentation site and ServerFault are full of correct configuration examples. – Alexander Azarov Oct 5 '11 at 21:55
feedback

Your Answer

 
or
required, but never shown

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