【问题标题】:Nginx proxy_pass cannot load assetNginx proxy_pass 无法加载资产
【发布时间】:2017-07-07 21:01:55
【问题描述】:

我正在用这个配置来配置 nginx:

location /test {
    proxy_pass http://127.0.0.1:10000;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
}

它可以工作,但没有所有资产。我检查元素,资产重定向到http://127.0.0.1:10000(绝对是404),它应该是http://127.0.0.1:10000/test/asset.css

需要建议:)

PS:我的服务器正在使用 angular2 (npm start)

【问题讨论】:

  • 你是怎么解决的。

标签: nginx reverse-proxy nginx-location


【解决方案1】:

愿原力与你同在:

location / {
    proxy_pass http://127.0.0.1:10000;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
}

location ~ ^/(images/|img/|javascript/|js/|css/|stylesheets/|flash/|media/|static/|robots.txt|humans.txt|favicon.ico) {
    root /root/of/your/public/assets;
    access_log off;
    expires max;
}

【讨论】:

  • 如果我有另一个网站,不冲突吗?
  • 只需创建服务器块,将其放入服务器块配置中。
猜你喜欢
  • 2020-09-16
  • 1970-01-01
  • 2019-05-26
  • 2021-09-19
  • 2020-06-19
  • 2020-04-28
  • 2021-05-10
  • 2019-05-08
  • 2020-04-11
相关资源
最近更新 更多