Rewriting nginx for pushState-URL's

后端 未结 5 2027
再見小時候
再見小時候 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:11

    Since there may be ajax request api, the following suits for this case,

    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;
        }
    
        # The location block above provides the shortest prefix, of length one, 
        # and so only if all other location blocks fail to provide a match, 
        # this block will be used.
    
        # Ajax api starts with /v1/ will be proxied
        location /v1/ {
            proxy_pass http://proxy;
        }
    }
    

提交回复
热议问题