One droplet, one domain, two parts of site in different locations (LEMP) - help!

June 5, 2016 432 views
Nginx LEMP Ubuntu 16.04

So I have 2 sites or rather parts of the same site but they have slightly different stacks/role. It will all sit under one droplet and same domain. Those parts are:

1. News site - accessible from homepage (mydomain.xyz) and a lot of pages after trailing slash /, static files only, no-db (I use flat file CMS)
2. Forum - that visitors are able to access under mydomain.xyz/forum/, PHP+MYSQL

Now, my concerns are, that if I add forum physically inside main site directory, there might be some sort of clutch between those 2 platforms. Think of it like having a ruby app nested inside of php app. To give you better picture:

Currently its like this - forum lives inside flat file CMS:

+site
   somefilesforsite.php
   +someotherdirectoriesforsite
        somemorefilesforsite.html
   +forum
       somefiles.php
       somedirctories
       +someforumdirectories
            somemorefilesforforum.html

I would prefer this way - have it all in separate directories:

+**site**
   somefiles.php
   somedirctories
   +

+**discuss**
   somefiles.php
   somedirctories

... yet I would like the forum to show under mydomain.xyz/forum like is literally inside directory of main/root site and:

a) this whole set-up it's secure - if in future I will add someone to maintain forum, they won't have an access to main site
b) if the main site is down for some reasons, users still have access to forum and vice-versa
c) I can configure for each their own nginx rules so they don't affect each other in any way (file permissions etc.)

...How to achieve that?

2 Answers
It's well known that the LEMP stack (Linux, nginx, MySQL, PHP) provides unmatched speed and reliability for running PHP sites. Other benefits of this popular stack such as security and isolation are less popular, though. In this article we'll show you the security and isolation benefits of running sites on LEMP with different Linux users. This will be done by creating different php-fpm pools for each nginx server block (site or virtual host).
  • Just checked out alias. If I understand correctly, for each - site & forum - I have completely separate nginx files in /etc/nginx/sites-available, like this:

    Second site for site:

    #/etc/nginx/sites-available/site
    server {
        listen      80;
        index index.html index.php;
    
        ## Begin - Server Info
        server_name mydomain.xyz; 
        root /home/[myuser]/site;
        ## End - Server Info
    
        location / { 
            try_files $uri $uri/ /index.php?$query_string;
        }
    }
    

    Second file forum for forum with alias parameter:

    #/etc/nginx/sites-available/forum
    server {
        listen      80;
        index index.html index.php;
    
        ## Begin - Server Info
        server_name mydomain.xyz; 
        root /home/[myuser]/forum;
        ## End - Server Info
    
        location / {
            alias /forum/;
        }
    }
    

    But if I state same server_name for both files, will that be served correctly in web browser?

P.S. There is mistake in example, should be +forum not "discuss", just posting to avoid confusion

+**site**
   somefiles.php
   somedirctories
   +

+**forum**
   somefiles.php
   somedirctories
Have another answer? Share your knowledge.