0

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?

Alister Bulman
  • 1,624
  • 13
  • 13

1 Answers1

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;
    }
}
quanta
  • 51,413
  • 19
  • 159
  • 217