結(jié)合 Nginx 將 DoNetCore 部署到 阿里云的安裝配置方法
基礎(chǔ)環(huán)境配置
域名和服務(wù)器請先自行購買
基于 云服務(wù)器ECS 創(chuàng)建一個應(yīng)用實例,選擇系統(tǒng)鏡像為 Ubuntu 16.04,在本機通過 SSH 進行遠程連接,并進行相關(guān)配置
ssh root@http://39.108.48.203/
... sudo apt-get update sudp apt-get upgrade sudo apt-get autoremove sudo apt-get clean
安裝并配置 Nginx
sudo apt-get install nginx sudo service nginx start sudo gedit /etc/nginx/sites-available/default
配置 default 文件,在文件末尾配置如下節(jié)點信息
# Virtual Host configuration for example.com # # You can move that to a different file under sites-available/ and symlink that # to sites-enabled/ to enable it. # server { listen 80; # 網(wǎng)站文件的目標位置 root /home/hippie/website/wwwroot; # 網(wǎng)站域名 server_name your website name; location / { proxy_pass http://localhost:5000; 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-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } }
檢測配置并更新
sudo nginx -t sudo nginx -s reload
安裝 DotNetCore
請參考官網(wǎng)最新安裝說明:.NetCore Download
部署流程
打開 VisualStudio2017 右鍵要發(fā)布的項目,點擊 publish,并參考下圖進行相關(guān)配置。
點擊 Save 按鈕并執(zhí)行發(fā)布操作。然后將 publish 文件夾上傳至服務(wù)器相應(yīng)位置,上傳成功后執(zhí)行
dotnet run app.dll
如果不出意外的,這個時候,你就可以通過 IP 或者 你的網(wǎng)站域名來進行訪問了。
創(chuàng)建守護進程
執(zhí)行上述操作之后,我們的程序還是不能正在長時間運行,因此我們需要通過守護進程來管理我們的網(wǎng)站
sudo apt-get install supervisor sudo vim /ect/supervisor/conf.d/website.conf
配置 website.conf 文件
[program:website] #要執(zhí)行的命令 command=/usr/bin/dotnet Attention.dll #命令執(zhí)行的目錄 directory=/home/hippie/website #環(huán)境變量 environment=ASPNETCORE__ENVIRONMENT=Production #進程執(zhí)行的用戶身份 user=www-data stopsignal=INT #是否自動啟動 autostart=true #是否自動重啟 autorestart=true #自動重啟間隔 startsecs=1 #標準錯誤日志 stderr_logfile=/var/log/website.err.log #標準輸出日志 stdout_logfile=/var/log/website.out.log
這個時候,我們執(zhí)行下述命令啟動守護進程
sudo supervisorctl shutdown && sudo supervisord -c /etc/supervisor/supervisord.conf supervisorctl shutdown sudo service supervisor start
好了,這個時候你可以嘗試關(guān)閉遠程連接進行網(wǎng)站訪問,如果能正常訪問的話,說明你的配置已經(jīng)起作用了.
總結(jié)
以上所述是小編給大家介紹的結(jié)合 Nginx 將 DoNetCore 部署到 阿里云的安裝配置方法,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復(fù)大家的!
相關(guān)文章
Nginx實現(xiàn)404錯誤自動跳轉(zhuǎn)到首頁的配置過程
當用戶在訪問網(wǎng)站的過程中遇到404錯誤時,通常情況下應(yīng)該顯示一個友好的錯誤頁面,而不是僅僅顯示一個簡單的錯誤提示,在Nginx中,可以通過配置來實現(xiàn)404錯誤自動跳轉(zhuǎn)到首頁的功能,下面將詳細介紹如何進行配置,需要的朋友可以參考下2023-12-12Nginx在Windows下的安裝及環(huán)境配置(將nginx作為服務(wù)運行)
這篇文章主要介紹了Nginx在Windows下的安裝及環(huán)境配置,主要是將nginx作為服務(wù)運行,需要的朋友可以參考下2018-11-11Nginx 502 bad gateway和Nginx 504 Gateway Time-out錯誤解決方法 錯誤解決辦
Nginx 502 Bad Gateway的含義是請求的PHP-CGI已經(jīng)執(zhí)行,但是由于某種原因(一般是讀取資源的問題)沒有執(zhí)行完畢而導(dǎo)致PHP-CGI進程終止2012-09-09