Welcome to Centmin Mod Community
Register Now

Nginx Single vHost - multiple root sources

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by Colin, Apr 29, 2016.

  1. Colin

    Colin Premium Member Premium Member

    108
    32
    28
    Oct 7, 2015
    Sheffield UK
    Ratings:
    +80
    Local Time:
    2:37 AM
    1.11.#
    MariaDB 10.1.#
    Hi folks,

    I hope this will make some sense, after a sanity check or a slap...

    I have a static html site at the example.com/ root location, served out of /home/nginx/domains/example.com/public folder. The static site replaces everything in this folder when deployed via git.

    I also want to run a php application out of say /app lets say thats located at /home/nginx/domains/example.com/app It also may get deployed with git/capistrano shared folders etc, it will be a forum / + shop application.

    As a visitor when I visit / I should see my static site, then when I visit /app I should see my php app.

    So far I've muddled this conf up, it is intrinsically the same as demodomain... is it 'sane' and can it be improved upon? PHP is not my forte anymore, if ever...

    Code:
    server {
                listen   80;
                server_name example.com;
                # limit_conn limit_per_ip 16;
                # ssi  on;
    
                access_log /home/nginx/domains/example.com/log/access.log ;
                error_log /home/nginx/domains/example.com/log/error.log error;
    
                root   /home/nginx/domains/example.com/public;
    
    location ^~ /app {
        root /home/nginx/domains/example.com;
        try_files $uri $uri/ =404;
        index index.html index.htm index.php;
    
        include /usr/local/nginx/conf/php.conf;
    }
         
    location / {
    #pretty empty atm
    }
          
    include /usr/local/nginx/conf/staticfiles.conf;
    include /usr/local/nginx/conf/php.conf;
    include /usr/local/nginx/conf/phpstatus.conf;
    include /usr/local/nginx/conf/drop.conf;
    #include /usr/local/nginx/conf/errorpage.conf;
    include /usr/local/nginx/conf/vts_server.conf;
    
    }
    
    
    I've modified /usr/local/nginx/conf/php.conf with:
    + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    - fastcgi_param SCRIPT_FILENAME $request_filename;

    At this point it's just to make it cough and splutter a php response, which it seems to do... my concern therefore is security, basedir and all the other stuff I've no idea about :D

    I'm coming from litespeed enterprise, but that's slightly different in that the app folder is in the public folder, with manual uploads :yuck yuck yuck:

    I'm toying with the SEO hit of going to app.example.com and a redirect. But then is app a sub part of the site when in reality it's the 99% visited part... :S
     
    • Informative Informative x 1