Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

NGINX configuration - multiple sites under same root path

  • 19-06-2018 03:24PM
    #1
    Registered Users, Registered Users 2 Posts: 250 ✭✭


    Hi

    I've been trying to configure NGINX for a REST app under the same root (and hostname), but I cannot seem to get it working.

    Assuming the root path is "/var/www/sandbox", the REST application (SLIM, PHP, index.php) would live in "/var/www/sandbox/api", whereas the WWW app (HTML, index.html) would live in "/var/www/sandbox/www".

    In the past, I would have either had 2 subdomains (for example www.sandbox.local and api.sandbox.local) or simply have the API folder within the WWW folder. I am keeping them separate for various reasons, but accessing them through one subdomain (www.sandbox.local), so I have tried 2 variations:

    Having a single ROOT, and an alias directive inside API location:
    server {
        listen       80;
        server_name  sandbox.local;
    
    	index	index.html;
     
        access_log  /var/log/nginx/sandbox-access.log;
        error_log /var/log/nginx/sandbox-error.log;
    
        root /var/www/sandbox/www;
    
        location / {
            try_files $uri $uri/ =404;
        }
    
        location /api {
            include   /etc/nginx/php/php-fpm;
            alias /var/www/sandbox/api;
            try_files $uri /index.php?$args;
        }
    }
    

    Specifying the roots inside each respective location block:
    server {
        listen       80;
        server_name  sandbox.local;
    
    	index	index.html;
     
        access_log  /var/log/nginx/sandbox-access.log;
        error_log /var/log/nginx/sandbox-error.log;
    
        location / {
            root /var/www/sandbox/www;
            try_files $uri $uri/ =404;
        }
    
        location /api {
            include   /etc/nginx/php/php-fpm;
            root /var/www/sandbox/api;
            try_files $uri /index.php?$args;
        }
    }
    

    Neither seems to work. I have done a few more straight forward configs with NGINX, and wouldn't consider myself an expert.

    Any help would be appreciated


Comments

Advertisement