Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How centos 7 deploys dotnetcore+Angular2

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to deploy centos 7 dotnetcore+Angular2, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

1. Prepare for

Project: aspnetcore+angular2 open source project template

Https://www.npmjs.com/package/generator-aspnetcore-angular2

This project uses webpack to package Angular2. If the intranet involves npm, please use tnpm.

two。 Environmental installation

(1) install dotnetcore

Https://www.microsoft.com/net/core#linuxcentos

Install according to official instructions

The installation guide given on the official website is to install dotnetcore 1.1, but the dotnetcore 1.0.1 used by our project

Therefore, 1.0.1 must be installed again (Note: multiple versions of dotnet core can coexist)

Curl-sSL-o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=827529tar zxf dotnet.tar.gz-C / opt/dotnet

(the download address is different)

(2) disable firewall

Systemctl stop firewalld.service # stop firewallsystemctl disable firewalld.service # disable firewall boot

As it is a learning project, you can turn off the firewall first. Please configure the firewall iptable in the build environment.

(3) install Nginx

Yum install nginx systemctl start nginx

It is normal to use the command line to test that curl http://127.0.0.1 can access html content

3. Project construction

(1) build the project

Build guidelines in windows environment refer to https://www.npmjs.com/package/generator-aspnetcore-angular2

Npm if you have access questions, you can use tnpm (http://tnpm.oa.com/)

Npm install-g yonpm install-g generator-aspnetcore-angular2

Create a project

Select Advanced template

Cancel npm installation and use tnpm

Compile the project

Compile dotnet, compile angular2

Dotnet assemblies restore,webpack package Angular2, run the project locally

Students who are interested can learn more about what the quick command has done.

Local access

Http://localhost:3000/

4. Deploy the project

(1) execute the release script

Dotnet publish

This command executes the project.json build command

"scripts": {

"prepublish": ["npm install", "npm run rebuild-sass", "npm run build"]

"postpublish": ["dotnet publish-iis-publish-folder% publish:OutputPath%-framework% publish:FullTargetFramework%"]

}

(2) compress the generated file

Table of contents:

\ test\ src\ test\ bin\ Debug\ netcoreapp1.0\ publish

Compressed into zip, and later uploaded to linux for deployment

(3) upload project

Use the ftp tool to upload only centos (the xshell+xftp I use)

Extract the file: unzip test.zip

(4) start the project

Set ASPNETCORE_ENVIRONMENT=Developmentdotnet test.dll server.urls= http://127.0.0.1:3000/

(note: localhost is not used here because of bind error under ip6)

It's already listening.

(5) testing

I found that although it opened our page, it actually made a mistake.

The Views\ Home\ Index.cshtml file needs to be modified

Loading...

Remove the following code

Asp-prerender-module= "wwwroot/src/server" asp-prerender-webpack-config= "webpack.config.js"

Curl test html is normal

(6) configure proxy

Port 3000 is not suitable for exposing public network, configure Nginx reverse proxy

Vim / etc/nginx/nginx.conf

Add 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

Check nginx configuration

Restart nginx

/ usr/sbin/nginx-t service nginx restart# get using reloadnginx-s reload

(7) View the results

Use the public network ip to access the site and directly access port 80

These are all the contents of the article "how to deploy dotnetcore+Angular2 in centos 7". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology