0

I'm trying to set up my environment such that surveyadmin.local points at one directory and surveyadmin.local/api points at another.

However, no matter what I change, the /api URL always results in a call to the directory that surveyadmin.local is pointing at. Here's a sample error from the error log specified in the vhost config:

2013/08/09 17:20:07 [error] 8911#0: *1 open() "/srv/http/surveytool/admin/build/app.php" failed (2: No such file or directory), client: 10.0.2.2, server: surveyadmin.local, request: "GET /api/organizations HTTP/1.1", host: "surveyadmin.local"

Note that the error refers to a path of /srv/http/surveytool/admin/buid/, instead of the /srv/http/surveytool/api/SurveyTool/web/ that was expected.

Here's my config for the vhost in question:

server {
    listen 80;
    server_name surveyadmin.local;

    location / {
        root /srv/http/surveytool/admin/build;
        index index.html;
    }

    location /api {
        root /srv/http/surveytool/api/SurveyTool/web;
        index app.php;
        try_files $uri $uri/ /app.php?$query_String;
        location ~ \.php(?|$) {
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index app.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include /etc/nginx/fastcgi_params;
        }
    }
    access_log  /var/log/nginx/surveyadmin.access.log;
    error_log   /var/log/nginx/surveyadmin.error.log debug;
}

I have tried changing the word "root" to "alias" under the location /api block. I've tried setting up a second virtual host and doing a proxy forward (with proxy_pass) to that vhost.

This seems like it shouldn't be that difficult, so I'm assuming my error is a simple one that I just haven't seen yet.

Can anyone spot any obvious problems with the above config?

1 Answer 1

0

Don't use root inside location blocks. This is one of the most common nginx misconfigurations.

Instead, place the root in the server block, and use alias inside location blocks that need specific directories outside the normal document root.

2
  • Aye, I've done that now, and it's looking in the right directory this time. However, it seems to be ignoring the try_files directive (which I've also moved outside of the location and into the server block). A request for /api/organizations should be served by app.php?querystring, but the error I get back implies that it's looking for a file called organizations. Aug 12, 2013 at 14:28
  • That sounds like a separate issue. Aug 12, 2013 at 14:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .