带有模板和资产的AngularJS HTML5模式的NGIX配置 [英] NGIX config for AngularJS HTML5 Mode with templates and assets

查看:98
本文介绍了带有模板和资产的AngularJS HTML5模式的NGIX配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在构建AngularJS应用,并希望在NGINX中使用HTML5模式.进行了重写以将所有流量定向到index.html.我遇到的问题是我所有的资产(图像,角度的模板文件等).那些也将被写回到index.html,因此它破坏了应用程序.关于nginx配置应该是什么样的任何想法.搜索时,没有看到任何可处理资产的内容.

Building an AngularJS app and want to use HTML5 mode with NGINX. Did a rewrite to direct all traffic to index.html. Problem I'm running into is all my assets (images, template files for angular, etc). Those are getting written back to index.html as well so it breaks the app. Any ideas on what the nginx config should look like. I'm not seeing anything that handles assets when I search.

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

推荐答案

这是一个非常肮脏的解决方案,因此它仅是一个临时解决方案,我希望在迁移到Angular 1.4时不再需要

This is a really dirty solution, so it's only for a temporary solution, i hope when migrate to Angular 1.4 this will not necesary

server {
    listen 0.0.0.0:12345;

    location / {
        root /home/zdwolfe/src/angularAWS/app;
        try_files $uri $uri/ /index.html =404;
    }
    error_page 404 /index.html
}

这篇关于带有模板和资产的AngularJS HTML5模式的NGIX配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆