小编Gla*_*ass的帖子

如何配置 Nginx 以提供来自 CDN 的静态文件

我有一个 SPA ( ReactJSwith React-Router)index.html用作入口点。为了使前端路由器正常工作,我需要index.html为所有匹配的 URL 返回文件。

我试过使用但proxy_pass失败了(见下文),

server {
    listen 80;
    proxy_set_header Host $http_host;
    proxy_set_header x-forwarded-for $remote_addr;


    location /appname/(?<section>.*) {
        proxy_pass http://cdn.us-west-2.edge.aws/666/index.html;
    }
}
Run Code Online (Sandbox Code Playgroud)

我也准备好了,try_files但这似乎只适用于本地文件。

我想要达到的效果,

  1. 当用户访问 http://example.com/appname
  2. http://cdn.us-west-2.edge.aws/666/index.html应提供静态内容


  1. 当用户访问 http://example.com/appname/abc
  2. http://cdn.us-west-2.edge.aws/666/index.html应提供静态内容


  1. 当用户访问 http://example.com/appname/abc/def
  2. http://cdn.us-west-2.edge.aws/666/index.html应提供静态内容

nginx

1
推荐指数
1
解决办法
7669
查看次数

标签 统计

nginx ×1