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 website running on Nginx, FastCGI and php-fpm, with a number of pages in subdirectories on it (that are run through the same front-controller as the rest of the website).

I'm looking for a configuration that will allow one of the sub-sites to be served from an alternate URL, such as http://site.johndoe.com/ - the same site, with the same front-controller producing it (an index.php at a given location on disk), but only showing the content of http://www.example.com/sub/site/ as a new domain.

In summary, the url: http://site.johndoe.com needs to transparently show the contents of http://www.example.com/sub/site/ - what rewrites and other server{} configurations are required with Nginx/FastCGI?

share|improve this question

1 Answer 1

All you have to do is create a new virtual host for site.johndoe.com and point document root to the /sub/site, something like this:

server {
    listen 80;
    server_name www.example.com;

    error_log /var/log/nginx/example.error_log info;

    root /document/root;

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        include fastcgi.conf;
        fastcgi_intercept_errors        on;
        error_page 404 /error/404.php;
    }
}

server {
    listen 80;
    server_name site.johndoe.com;

    error_log /var/log/nginx/johndoe.error_log info;

    root /document/root/sub/site;

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        include fastcgi.conf;
        fastcgi_intercept_errors        on;
        error_page 404 /error/404.php;
    }
}
share|improve this answer

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.