nginx: send all requests to a single html page

前端 未结 6 2064
南笙
南笙 2020-11-30 17:45

Using nginx, I want to preserve the url, but actually load the same page no matter what. I will use the url with History.getState() to route the requests in my

6条回答
  •  醉酒成梦
    2020-11-30 18:02

    This worked for me:

    location / {
        alias /path/to/my/indexfile/;
        try_files $uri /index.html;
    }
    

    This allowed me to create a catch-all URL for a javascript single-page app. All static files like css, fonts, and javascript built by npm run build will be found if they are in the same directory as index.html.

    If the static files were in another directory, for some reason, you'd also need something like:

    # Static pages generated by "npm run build"
    location ~ ^/css/|^/fonts/|^/semantic/|^/static/ {
        alias /path/to/my/staticfiles/;
    }
    

提交回复
热议问题