在使用angular2开发项目的时候,你会发现ng build出来的包,动不动就几m啊(没有黑angular的意思),那还怎么玩下去啊,对吧。虽然angular2有aot啊,但是优化之后还是很大啊,那怎么办啊?要不试试gzip啊。
那么我就用Nice Fish(http://git.oschina.net/mumu-osc/NiceFish)为例,来说下如何使用nginx运行angular2的项目以及开启gzip,加快访问速度。
先来看下怎么配置nginx,然后将nginx作为前端代码的服务器。
server {
listen 80;
server_name 127.0.0.1;
#access_log logs/access.log;
root /Users/zhongzhong/workspace/NiceFish/dist;
#error_page 404 /index.html;
location / {
try_files $uri $uri/ /index.html;
}
location /api {
proxy_pass http://127.0.0.1:8080/NiceFish;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_intercept_errors on;
}
location ~* \.(js|css|png|gif|jpg|mp3|ogg|ttf|woff|woff2|html|json|map)$ {