views:

12

answers:

0

When users come to / they should be served a static index.html file.

When they come to /foobar the request should be sent to the backend server.

However, this is not the case, with the following:

pid               logs/nginx.pid;
worker_processes  2;

events {
    worker_connections 1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    charset       utf-8;

    ## Proxy settings ##
    server {
        listen       127.0.0.1:8080;
        server_name  example.com;
        access_log   logs/proxy.access.log;
        error_log    logs/proxy.error.log;

        # define the root of the static files
        # send index.html on EXACTLY /
        root ../web/;
        location = / {
            index index.html;
        }

        # a rewrite to support /s -> /s/
        # send index.html on /s/
        rewrite ^/s$ /s/ permanent;
        location /s/ {
            index index.html;
            alias ../web/;
        }

        location / {
            proxy_set_header   Host             $host;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

            proxy_pass          http://127.0.0.2:8080;
            proxy_read_timeout  600;
            proxy_buffering     off;
        }
    }
}

What happens is that it contacts the backend server on all request, except /s and /s/. That means that / does not return the /index.html file.

Isn't the 'location = /' supposed to guarantee that this is always chosen if there is an exact match?