I have nginx running and want to serve an static application at the URL https://example.com/myapp
.
I have a server
block like so:
server {
listen 443 ssl http2;
server_name example.com;
root /var/www/html;
location /myapp/ {
root /home/tri/myapp/dist;
rewrite ^/myapp/?(.*)$ /$1 break;
}
}
I expect that by going to https://example.com/myapp
, it will serve the index.html
file, but that's not the case.
If I go to https://example.com/myapp/index.html
, the file is served correctly. However, if I just go to https://example.com/myapp
, I get this error in nginx:
2020/03/28 15:17:40 [error] 27905#27905: *11410 open() "/var/www/html/index.html" failed (2: No such file or directory), client: 73.119.123.242, server: example.com, request: "GET /myapp/ HTTP/2.0", host: "example.com"
So for some reason, it's falling back to the default root
directive.
What am I doing wrong here?