Nginx proxy_pass无法加载资产

时间:2017-02-18 08:55:42

标签: nginx reverse-proxy nginx-location

我使用此配置配置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)

1 个答案:

答案 0 :(得分: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;
}