首頁 > 運維 > Nginx > Nginx怎麼將DoNetCore部署到阿里雲

Nginx怎麼將DoNetCore部署到阿里雲

PHPz
發布: 2023-05-13 22:37:11
轉載
1080 人瀏覽過

基礎環境配置

網域和伺服器請先自行購買

基於雲端伺服器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://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;

 }

}

登入後複製

偵測設定並更新

1

2

sudo nginx -t

sudo nginx -s reload

登入後複製

#安裝dotnetcore

請參考官網最新安裝說明:.netcore download

部署流程

開啟visualstudio2017 右鍵要發佈的項目,點選publish,並參考下圖進行相關設定。

Nginx怎麼將DoNetCore部署到阿里雲

Nginx怎麼將DoNetCore部署到阿里雲

點擊 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中文網其他相關文章!

相關標籤:
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板