I have a simple default website configuration located in my "sites-available" folder in nginx that looks like the one below.

When I try browse to /hello I'd expect it to serve the index.html file located in the root folder I specified. Instead, it is trying to get /hello/index.html within the root location I specified.

Is there a way to tell nginx to serve the files without prefixing the context path?

root /var/...;

location / {

location /hello/ {
    root /home/vagrant/public_html/project/dist;
  • You do know that nginx looks at the sites-enabled directory and not sites-available? There should be a symlink from the former to the latter for those sites that should be enabled. Perhaps you've edited a config that's not enabled and hence not being picked up.
    – wurtel
    Commented Nov 14, 2014 at 9:18
  • Yes, I should have mentioned that. As practice, I always work on sites-available and symlink what's ready on sites-enabled (which is what I did this case).
    – Pablo
    Commented Nov 16, 2014 at 21:08
  • 1
    Did you try browsing to /hello as you write, or to /hello/ as the location line specifies? (Note the trailing slash in the latter.)
    – wurtel
    Commented Nov 17, 2014 at 7:45

1 Answer 1


Use alias instead of root; quoting http://nginx.org/en/docs/http/ngx_http_core_module.html#alias

For example, with the following configuration

location /i/ {
    alias /data/w3/images/;

on request of “/i/top.gif”, the file /data/w3/images/top.gif will be sent.

You must log in to answer this question.

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