本篇內容主要講解“Nginx怎么將DoNetCore部署到阿里云”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“Nginx怎么將DoNetCore部署到阿里云”吧!
基礎環境配置
域名和服務器請先自行購買
基于 云服務器ecs 創建一個應用實例,選擇系統鏡像為 ubuntu 16.04,在本機通過 ssh 進行遠程連接,并進行相關配置
ssh
... 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 文件,在文件末尾配置如下節點信息
# 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;
# 網站文件的目標位置
root /home/hippie/website/wwwroot;
# 網站域名
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
請參考官網最新安裝說明:.netcore download
部署流程
打開 visualstudio2017 右鍵要發布的項目,點擊 publish,并參考下圖進行相關配置。


點擊 save 按鈕并執行發布操作。然后將 publish 文件夾上傳至服務器相應位置,上傳成功后執行dotnet run app.dll
如果不出意外的,這個時候,你就可以通過 ip 或者 你的網站域名來進行訪問了。
創建守護進程
執行上述操作之后,我們的程序還是不能正在長時間運行,因此我們需要通過守護進程來管理我們的網站
sudo apt-get install supervisor sudo vim /ect/supervisor/conf.d/website.conf
配置 website.conf 文件
[program:website] #要執行的命令 command=/usr/bin/dotnet attention.dll #命令執行的目錄 directory=/home/hippie/website #環境變量 environment=aspnetcore__environment=production #進程執行的用戶身份 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
這個時候,我們執行下述命令啟動守護進程
sudo supervisorctl shutdown && sudo supervisord -c /etc/supervisor/supervisord.conf supervisorctl shutdown sudo service supervisor start
好了,這個時候你可以嘗試關閉遠程連接進行網站訪問,如果能正常訪問的話,說明你的配置已經起作用了.
到此,相信大家對“Nginx怎么將DoNetCore部署到阿里云”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。