Rewriting nginx for pushState-URL's

后端 未结 5 2022
再見小時候
再見小時候 2020-12-04 11:27

I am trying to get nginx to work with my pushState-based URI handling that backbone.js manages for me in an Javascript app.

R

5条回答
  •  甜味超标
    2020-12-04 12:08

    I ended up going with this solution:

    server {
    
        listen 80;
        server_name example.com;
        root /var/www/example.com;
    
        # Any route containing a file extension (e.g. /devicesfile.js)
        location ~ ^.+\..+$ {
            try_files $uri =404;
        }
    
        # Any route that doesn't have a file extension (e.g. /devices)
        location / {
            try_files $uri /index.html;
        }
    
    }
    

    This way, at least I still get proper 404 errors if a file isn't found.

提交回复
热议问题