nginx config for multiple drupal installations

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
Anonymous's picture

I have been looking/trying this but couldn't find perfect solutions. I was testing multiple Drupal installations and my configs is like

server {
    server_name localhost;
    listen 80;
    root /var/www/mainsite;
}

I have main site which has a link to forum and I have forum site in /var/www/forum; The main site and forum site has their own settings.php and files. It is just separate project but linked with each other, as the forum has link to main site via home button.

how do I acheive this with Nginx, I tried

server {
    server_name localhost;
    listen 80;
    root /var/www/forum;
}

which doesn't work. somebody suggested to have a location directive, and I tried something like
location / {
    location /forum/ {
    root /var/www/mainsite;
}

it gives me access denied error, which is php-fpm access denial error.

Any woraround would be appreciated.

Comments

Have you tried using

Garrett Albright's picture

Have you tried using perusio's config? If you use it, setting up a new site for your server is a matter of copying a config file and editing in the relevant domain name and file path.

Hi fully_stoned, I would

scottm316's picture

Hi fully_stoned,
I would think you will need a combination of both of those directives. In fact, seeing how they are 2 separate projects/sites, I'd probably make a server block for both separately, each with their own location blocks. Off the top of my head (do not use this exactly obviously):

server {
        listen 80;
  server_name example.com;
   root        /var/www/mainsite/;
        location / {
          ...
          ...  # drupal/nginx config stuff here
          ...
          ...  # location specific stuff for this site, nested in like:

          location ~* ^/(update|install|test|authorize|xmlrpc).php$ {
                        fastcgi_pass   $php_socket;  # or however you do it
                include fastcgi_params;
                try_files $uri =404;
           }
          ...
          ... # more blocks like the above to deal with your website
          ...
          try_files $uri @drupal;  #or however you're doing it
          ...
          ...
       }   # closes "location /" block
} # closes server block

Then in another file, or the same further down, I would just make another server block since the forum is in an adjacent and separate folder:
server {
        listen 80;
  server_name myforum.com;
   root        /var/www/forum;
        location / {
          ...
          ...  # forum nginx config stuff here
          ...
          ...  # location specific stuff for forum, nested in like above

          location ~* ^/(admin|forum-admin).php$ {
                        fastcgi_pass   $php_socket;  # or however you do it
               include different_fastcgi_params;
              try_files $uri =404;
           }
          ...
          ... # more blocks like the above to deal with your website
          ...
       }   # closes location / block
} # closes server block

I think it's pretty useful how you can define a parent location block (location / {}) and it can contain location sub-blocks to deal with more specific stuff.

As far as access denied, check that the nginx user specified in your nginx.conf file has permissions to read AND execute the files it's trying to serve, as well as all of its parent folders.

Mr. Albright, I am quite sure anyone posting questions in the group has either tried perusio's config, read through perusio's config (link in group header), and/or understands enough nginx to be able to ask specific questions about their own config. Consistently responding to every new post with "Have you tried perusio's config" doesn't exactly help anyone.

I agree my question doesn't look clear

fully_stoned's picture

@Garrett: I guess Nginx-for-Drupal has become synonym to Perusio's config, and yes I am using his config for D7.

@scott: Thanks for response, I have tried with the same setup as you suggested before posting here. The problem is I don't have subdomain or two domain names for forum and main site, if the main site is example.com the forum site is example.com/forum and the forum is different drupal installation with its own settings.php and separate database.

multisite?

emjayess's picture

the main site is example.com the forum site is example.com/forum and the forum is different drupal installation with its own settings.php and separate database.

It's not clear why there are two distinct installations to achieve this... not that it needs to be, and not that you don't have a good reason (I'm sure you do)... but it does seem overcomplicated.

Regardless, from your comment, are the two installations actually (physically) separate? Or are they configured like a multi-site installation? If the question isn't clear, you may benefit from reviewing the MULTISITE CONFIGURATION section of the INSTALL.txt file. I haven't done a multi-site in awhile (or at all with D7), but I suspect it might make the nginx side of the config somewhat simpler... perhaps just a typical drupal-with-nginx server block.

--
matt j. sorenson, g.d.o., d.o.

not multisite but multiple installations

fully_stoned's picture

Yes, you are right, two installations are physically separate too. Its kind of complicated configuration, but well planned for future scalability and high availability.

Perhaps redeclaring the whole nginx block inside one location block might be the solution, like

location / {
    location /forum/ {
        # forum root and all drupal locations here
    }
    # main site config and all drupal location here
}

but haven't tried it yet, I guess if I have to go with this kind of setup, I need to define absolute path for every location block.

You need

perusio's picture

to copy the drupal.conf file and add forum at the beginning. So location / becomes /forum and all exact locations like = /favicon become = /forum/favicon.ico. In a nutshell all non regex based location need a /forum at the beginning. Then include both files in your vhost config. Let's call the forum site config file drupal_forum.conf. Include both in the vhost.