Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

NGINX configuration - multiple sites under same root path

Options
  • 19-06-2018 3:24pm
    #1
    Registered Users 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