chris
chris

Reputation: 2951

How to install one site inside another with Nginx

I have a wordpress multisite on centos 6.5 at /var/www/html/site1 accessible at site1.com and everything there is fine.

I would like to install a single site called site2 at /var/www/html/site2 but accessible at site1.com/site2

The .conf for site1 has a server block like this:

            location / {
                         try_files $uri $uri/ /index.php?$args;
                       }

            #editing here to...
            location /site2 {
                root /var/www/html/site2/;
                index index.php index.html index.htm;
                try_files /index.html /index.php $uri $uri/;
             }

             location ~ /site2/(.*\.php)$ {
                root /var/www/html/site2/;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$1;
                include /etc/nginx/fastcgi_params;

                location ~ \.php$ {
                     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;
                 }

            }

          #end editing. 

When I use try files try_files /index.html /index.php $uri $uri/; it works. When I use try_files try_files /index.php $uri $uri/; the browser downloads the file instead of displaying it.

Upvotes: 0

Views: 176

Answers (1)

Steffen
Steffen

Reputation: 599

The location block should do the trick as long as you define a new root for the location:

location /site2
{
  root /var/www/html/site2;

  #put your rewrite rules here
}

You have to make sure that your fastcgi (I assume you'r using php-fpm) configuration uses the new docroot as well. I don't know wordpress very well, but I reckon you also have to configure the second site to be in a subdirectory called /site2, otherwise links might not work properly.

Upvotes: 0

Related Questions