【发布时间】:2018-04-06 16:45:23
【问题描述】:
我一直在尝试研究 Nginx 以在 localhost:4200 上配置具有 Angular 5 ng 服务的代理,但只提供服务已构建项目的结果。我从这项研究中发现的配置“有点”有效,但会导致出现未加载任何数据的白页:
dev:12 GET http://192.168.1.84/inline.bundle.js net::ERR_ABORTED
dev:12 GET http://192.168.1.84/polyfills.bundle.js net::ERR_ABORTED
dev:12 GET http://192.168.1.84/styles.bundle.js net::ERR_ABORTED
dev:12 GET http://192.168.1.84/vendor.bundle.js net::ERR_ABORTED
dev:12 GET http://192.168.1.84/main.bundle.js net::ERR_ABORTED
它似乎看不到 ng serve 提供的文件,但至少可以到达项目的 index.html 页面。这是我目前使用的配置:
location /dev {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
rewrite ^/(.*)$ /$1 break;
proxy_set_header Host localhost;
proxy_pass http://localhost:4200;
}
我应该在 /dev 配置中添加什么?
【问题讨论】: