【问题标题】:How to serve Angular 2 SPA with Routes from Azure Blob via Azure Verizon Premium CDN如何通过 Azure Verizon Premium CDN 从 Azure Blob 为 Angular 2 SPA 提供路由
【发布时间】:2017-11-27 04:52:08
【问题描述】:

https://docs.microsoft.com/en-us/azure/cdn/cdn-rules-engine-reference-features 此处没有足够的关于重写规则的文档。刷新也需要 4 小时,因此尝试各种正则表达式组合是不切实际的。

我有一个托管在 Azure Blob 上的 Angular 2 单页应用程序(英雄示例应用程序),并希望从 Azure CDN 提供它。但是,Angular 2 路由需要特殊处理,即将路由重写为 index.html。这是我使用 NGINX 代理的工作示例。如何将其转换为 Azure Verizon Premium CDN?

# Filename: /etc/nginx/nginx.conf
http {
    ...
    rewrite_log on;

    server {
        listen       80;
        server_name  www.heroes.com;

        proxy_connect_timeout       600;
        proxy_send_timeout          600;
        proxy_read_timeout          600;
        send_timeout                600;

        location / {
            error_log /var/log/nginx/rewrite.log notice;
            rewrite '^(\/(\w+))*\/?(\.\w{5,})?\??([^.]+)?$' /heroes/index.html break;
            proxy_pass https://xxxxxx.blob.core.windows.net/heroes/;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header        X-Forwarded-Proto https;

        }
    }
}

【问题讨论】:

标签: angularjs azure nginx azure-cdn


【解决方案1】:

您可以使用存储帐户上的“静态网站”选项在 Azure 静态网站上使用 angular 2+。无需重写规则。

请务必添加“index.html”作为“索引文档名称”和“错误文档路径”(否则刷新或初始请求将失败)

【讨论】:

  • 非常感谢!你拯救了我的一天!
  • 此解决方案将为其他 URL 显示正确的页面,但它们提供 404 状态代码,这是非常不幸的。
猜你喜欢
  • 2023-03-29
  • 2018-03-28
  • 2021-06-20
  • 2021-03-19
  • 2018-03-28
  • 2021-07-30
  • 2020-09-26
  • 2021-04-05
  • 2018-12-05
相关资源
最近更新 更多