標籤:0.12 win10 src win8 macos 安裝完成 stp 配置 access
開發環境:Win10
開發工具:Visual Studio 2015
部署環境:centos 7-x64或macOS 10.12
一、準備工作
(一)開發機器
1. 安裝VS2015 .NET Core開發工具:Visual Studio 2015 Tools (Preview 2),:https://go.microsoft.com/fwlink/?LinkId=827546;
2. 安裝.NET Core SDK,:https://go.microsoft.com/fwlink/?LinkID=835009;
3. ASP.NET Core程式可以使用命令列啟動Web服務,如果需要使用IIS,還要下載一個伺服器:Windows Server Hosting,:https://aka.ms/dotnetcore_windowshosting_1_1_0
(二)部署機器
1. 安裝.NET Core環境
(1)CentOS安裝方法詳見:https://www.microsoft.com/net/core#linuxcentos;
(2)macOS安裝方法詳見:https://www.microsoft.com/net/core#macos
2.安裝Nginx
(1)CentOS安裝方法詳見:http://blog.csdn.net/renminzdb/article/details/48948165;
(2)macOS安裝方法:終端中輸入“brew install nginx”,安裝完成之後,輸入“nginx -v”查看是否安裝成功。
二、開發
(一)建立.Net Core程式
(二)修改Project.json檔案
1. 將“type”這一句注釋掉
1 "dependencies": { 2 "Microsoft.NETCore.App": { 3 "version": "1.0.0" 4 //"type": "platform" 5 }
2. 將“postpublish”這一句注釋掉
1 "scripts": { 2 "prepublish": [ "bower install", "dotnet bundle" ] 3 //"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] 4 }
3. 加上“runtimes”,將需要發布的平台寫上
1 "scripts": { 2 "prepublish": [ "bower install", "dotnet bundle" ] 3 //"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] 4 }, 5 "runtimes": { 6 "centos.7-x64": {}, 7 "osx.10.10-x64": {}, 8 "win10-x64": {}, 9 "win8-x64": {}, 10 "win81-x64": {} 11 }
(三)發布
1. 開啟CMD,進入程式目錄“src\項目名”,執行“donnet restore”;
2. 執行“dotnet publish –r centos.7-x64”,如果是macOS則是“dotnet publish –r osx.10.10-x64”(macOS 10.12測試也可用);
3. 複製“src\項目名\bin\Debug\netcoreapp1.0\centos.7-x64”到CentOS或macOS機器上。
三、部署
(一)運行程式
1. 運行”終端“,進入程式目錄,輸入”dotnet 程式入口檔案名稱.dll“(如”dotnet WebApp1.dll”或“dotnet ConsoleApp1.dll”等),當前視窗不要關閉;
2. 如果是ASP.NET Core程式,輸入網址(如 http://localhost:5000),看服務是否已經正常啟動。
(二)配置 Nginx 代理
1. macOS配置:
安裝完 nginx 之後,預設的設定檔路徑在 /usr/local/etc/nginx 檔案夾中。在這個檔案夾中找到nginx.conf 設定檔,使用 Visual Studio Code 開啟,在 Server 節點中,找到監聽 80連接埠的location 節點,修改配置為如下:
1 server { 2 listen 80; 3 4 #root /usr/share/nginx/html; 5 #index index.html index.htm; 6 7 # Make site accessible from http://localhost/ 8 server_name localhost; 9 10 location / { 11 proxy_pass http://localhost:5000; 12 proxy_http_version 1.1; 13 proxy_set_header Upgrade $http_upgrade; 14 proxy_set_header Connection keep-alive; 15 proxy_set_header Host $host; 16 proxy_cache_bypass $http_upgrade; 17 } 18 }
儲存並退出, 然後使用sudo nginx -s reload命令來重新載入配置。
然後我們開啟瀏覽器 輸入http://localhost,發現此時已經通過 Nginx 來訪問我們的網站了。
2. CentOS配置:
安裝完 nginx 之後,預設的設定檔路徑在 /etc/nginx/sites-available/default 檔案中。切換工作目錄到/etc/nginx/sites-available/,使用sudo gedit default命令開啟 default 檔案。
後續操作跟上述macOS的操作相同。
跨平台部署.NET Core程式