A
A
Artyom2015-10-01 02:00:48
Nginx
Artyom, 2015-10-01 02:00:48

What to write in Nginx config to serve .html?

There is this config:

server {
    listen 0.0.0.0:80;
    server_name  doc.ixley.ru;
    root         /var/www/doc.ixley.ru/out/;
    index index.html index.htm;
}

At the address doc.ixley.ru it returns index.html from doc.ixley.ru/out/
But at the address doc.ixley.ru/pages/hello it should return hello.html, but it does not return it, more precisely it returns it if you go to the address doc .ixley.ru/pages/hello.html, but there is no way without the .html extension prefix .
And one more thing:
In the home folder there is a pages folder and a posts folder.
The pages folder contains the hello.html file (just a page) and posts.html (the page displays a list of posts from the posts folder)
And in the posts hello.html folder (this is a post)
We have two identical hello.html file names, but located in different places
Please help me take this into account. I note that I only need to know how to take into account the paths, reflection of posts in files, etc. is not necessary, this is compiled separately and then it will be reflected in the files itself.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2015-10-02
@ixley

You can try something like this:

server {
    listen 80;
    server_name doc.ixley.ru;
    root /var/www/doc.ixley.ru/out/;
    index index.html index.htm;

    location / {
        try_files $uri $uri.html $uri/ =404;
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question