I have two sites that I need to serve: a static one and a dynamic one (Rails app, doesn't really matter actually). I'm thinking about the following:
requests to domain.com/ => Static website
requests to domain.com/anything => Dynamic website
Nginx's location directive seems perfect for this situation:
server { listen 80; server_name www.domain.com *.domain.com; # Static match. Any exact match enters here location = / { root /link/to/static/folder; index index.html; } # Dynamic match location / { root /link/to/dynamic/folder; proxy_pass unix_socket_defined_above; } } But whenever I make a request to domain.com it gets directed to the dynamic match. What am I missing?
Edit: Although it is not optimal, I'm achieving the desired functionality with the following declarations:
server { listen 80; server_name domain.com .domain.com; # Static match. Any exact match enters here location = / { root /link/to/static/folder; index index.html; } # Dynamic match, make sure the URL has # characters after the server name location ~ ^/..* { root /link/to/dynamic/folder; proxy_pass unix_socket_defined_above; } } but I'm sure there's a "right way" to accomplish this.