Search code examples
vue.jsnginxprerender

How do I config nginx to serve any path to a single specific html file?


I use Vue and prerender a index.html, and the Vue entry file app.html. I need to configure nginx to serve by the following rules:

www.mydomain.com/ => go to /data/www/index.html
www.mydomain.com  => go to /data/www/index.html
www.mydomain.com/anything => anything else go to /data/www/app.html

Here is what I wrote in ngnix.conf but it's not working:

server_name www.mydomain.com;
root /data/www/mydomain/;
location / {
            try_files $uri $uri/ $uri/index.html $uri/app.html /app.html ;
}

It does not serve app.html in any circumstance. How do I configure to achieve that? Thanks.


Solution

  • Can you try this one?

    location = / {
        rewrite . /index.html break;
    }
    location / {
        rewrite . /app.html break;
    }