微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

[Nginx] Configuration for SPA

server {
    listen 0.0.0.0:80;
    listen [::]:80;
    default_type application/octet-stream;

    gzip                    on;
    gzip_comp_level         6;
    gzip_vary               on;
    gzip_min_length         1000;
    gzip_proxied            any;
    gzip_types              text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+RSS text/javascript;
    gzip_buffers            16 8k;
    client_max_body_size    256M;

    root /usr/share/Nginx/html;

    location / {
        try_files $uri $uri/ /index.html =404;
    }
}

 

The highlighted part is important, without this, if you hint the page url:

http://localhost:8080/orders/1

It will show 404 page, because it will be regareded as a server request.

 

With this line of code, it will return index.html, then Frontend framework can handle with the router.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。