版权声明:本文由屈政斌原创文章,转载请注明出处:
文章原文连接:https://www.qcloud.com/community/article/239html
来源:腾云阁 https://www.qcloud.com/communitylinux
服务器: 腾讯云主机(Centos 7.1)webpack
项目:aspnetcore+angular2 开源项目模版nginx
该项目使用webpack 打包Angular2, 内网涉及到npm请使用tnpmweb
根据官方指导进行安装;shell
官网给出的安装引导是安装dotnet core 1.1 ,可是咱们项目使用的dotnetcore 1.0.1npm
因此必须再安装1.0.1 (备注dotnet core 能够多个版本并存)json
curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=827529 tar zxf dotnet.tar.gz -C /opt/dotnet
(下载的地址不同)vim
systemctl stop firewalld.service #中止firewall systemctl disable firewalld.service #禁止firewall开机启动
因为是学习项目,能够先关闭防火墙, 生成环境请配置防火墙iptablewindows
yum install nginx systemctl start nginx
使用命令行测试 curl http://127.0.0.1 能访问到html内容则正常
在windows环境 构建 指引 参考
npm若是访问问题可使用tnpm
npm install -g yo npm install -g generator-aspnetcore-angular2
选择高级模版
取消npm 安装 使用 tnpm
编译dotnet ,编译angular2
dotnet 程序集restore,webpack 打包Angular2 ,本地运行项目
有兴趣的同窗能够多了解快命令具体作了啥
dotnet publish
该命令会执行project.json 的构建命令
"scripts": { "prepublish": [ "npm install", "npm run rebuild-sass", "npm run build" ], "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] }
目录:
\test\src\test\bin\Debug\netcoreapp1.0\publish
压缩成zip ,稍后上传到linux进行部署
使用ftp工具上传只centos (我使用的xshell+xftp)
解压文件: unzip test.zip
set ASPNETCORE_ENVIRONMENT=Development dotnet test.dll server.urls=http://127.0.0.1:3000/
(备注 此处没有使用localhost ,是由于ip6 下bind错误 )
已经监听了
5.测试
发现上面虽然打开了咱们的页面实际上是爆了一个错误
须要修改 Views\Home\Index.cshtml 文件
<app-root asp-prerender-module="wwwroot/src/server" asp-prerender-webpack-config="webpack.config.js"> Loading... </app-root>
去掉以下代码
asp-prerender-module="wwwroot/src/server" asp-prerender-webpack-config="webpack.config.js"
curl 测试html正常
3000端口不适合暴露外网, 配置Nginx 反向代理
vim /etc/nginx/nginx.conf
添加 cgi
proxy_pass http://127.0.0.1:3000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
检查nginx配置
重启nginx
/usr/sbin/nginx -t service nginx restart #获取使用reload nginx -s reload
使用外网ip访问站点, 直接访问80端口就行了
该项目目前只是用于学习dotnetcore ,Angular2 , 顺便熟悉一下 npm,webpack,linux。