6

I want to archive that serving variable html file through different uri, below is my config.

server {
  listen 8888;
  server_name localhost;

  location / {
    root html/test
    index foo.html
  }

  location /another {
    root html/test
    index bar.html
  }
}

I want request for localhost:8888/another then response bar.html which present in my test directory, but I'm failed :(

how could I fix above config, thanks for your time.

1 Answer 1

4

The filename is constructed from the value of the root directive and the URI. So in this case:

location /another {
    root html/test;
    index bar.html;
}

The URI /another/bar.html will be located at html/test/another/bar.html.

If you want the value of the location directive to be deleted from the URI first, use the alias directive.

location /another {
    alias html/test;
    index bar.html;
}

The URI /another/bar.html will be located at html/test/bar.html.

See this document for details.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.