基礎環境配置
網域和伺服器請先自行購買
基於雲端伺服器ecs 建立一個應用實例,選擇系統鏡像為ubuntu 16.04,在本機透過ssh 進行遠端連接,並進行相關配置
ssh
1 2 3 4 5 6 | ...
sudo apt-get update
sudp apt-get upgrade
sudo apt-get autoremove
sudo apt-get clean
|
登入後複製
安裝並配置nginx
1 2 3 | sudo apt-get install nginx
sudo service nginx start
sudo gedit /etc/nginx/sites-available/ default
|
登入後複製
配置default 文件,在文件末尾配置如下節點資訊
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # 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:
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 ;
}
}
|
登入後複製
偵測設定並更新
1 2 | sudo nginx -t
sudo nginx -s reload
|
登入後複製
#安裝dotnetcore
請參考官網最新安裝說明:.netcore download
部署流程
開啟visualstudio2017 右鍵要發佈的項目,點選publish,並參考下圖進行相關設定。


點擊 save 按鈕並執行發布操作。然後將publish 資料夾上傳至伺服器對應位置,上傳成功後執行
dotnet run app.dll
如果不出意外的,這個時候,你就可以透過ip 或者你的網站域名來進行訪問了。
建立守護程式
執行上述操作之後,我們的程式還是無法正在長時間運行,因此我們需要透過守護程式來管理我們的網站
1 2 | sudo apt-get install supervisor
sudo vim /ect/supervisor/conf.d/website.conf
|
登入後複製
配置website.conf 檔案
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | [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
|
登入後複製
這個時候,我們執行下述命令啟動守護程序
1 2 3 | sudo supervisorctl shutdown && sudo supervisord -c /etc/supervisor/supervisord.conf
supervisorctl shutdown
sudo service supervisor start
|
登入後複製
好了,這個時候你可以嘗試關閉遠端連線進行網站訪問,如果能正常存取的話,說明你的配置已經起作用了.
以上是Nginx怎麼將DoNetCore部署到阿里雲的詳細內容。更多資訊請關注PHP中文網其他相關文章!