Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to serve from

Within nginx.conf I tried putting mypage.html in designated root directory and then

location /mypage}
 alias mypage.html;

But no dice. Must be something similar?

Edit: If I put entire path from '/' in alias it works but I would rather have it relative from the set root directory. How do I reference the root dir I have defined earlier in the config with:

root /usr/share/nginx/www;

Further, when I do this and the client makes a request for /mypage, nginx defaults to octet stream filetype. How do I force text/html for URLs I define like this?

share|improve this question
up vote 4 down vote accepted

You can add the following to your location / block to make it work for all pages. This will first try to serve the requested uri, if that doesn't work it will try to serve it with an html extension (without adding it to the url)

location / {
    try_files $uri $uri.html $uri/ /index.html;

or if you want it only to work with one page you can add the following to your server block

location ~ /mypage {
    try_files $uri.html /index.html;
share|improve this answer
what is the ~ for? – user1561108 Nov 29 '12 at 1:20
Check this page for the various regex options: – jagsler Nov 29 '12 at 1:30
@user1561108 "~" for case sensitive matching #1 – jberger Nov 7 '13 at 21:52

You must log in to answer this question.

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