JAVA和Nginx 教程大全

网站首页 > 精选教程 正文

用 Nginx 部署 ASP.NET Core 应用程序

wys521 2024-10-17 15:36:25 精选教程 35 ℃ 0 评论

用 Nginx 部署 ASP.NET Core 应用程序步骤如下:

  1. 在Linux中安装.NET Core运行时和Nginx:

a) 在Linux中打开终端。

b) 确认您的Linux发行版是否支持.NET Core并安装它。

c) 根据自己的版本安装.NET Core运行时和SDK:

sudo apt-get update

sudo apt-get install dotnet-runtime-5.0

sudo apt-get install dotnet-sdk-5.0

d) 安装Nginx:

sudo apt-get install nginx
  1. 创建基本的ASP.NET Core Web应用程序:

a) 创建一个新的ASP.NET Core Web应用程序:

dotnet new web -n MyAspNetCoreApp

b) 导航到应用程序目录:

cd MyAspNetCoreApp
  1. 构建应用程序并发布:

a) 构建应用程序:

dotnet build

b) 发布应用程序:

dotnet publish -c Release
  1. 配置Nginx服务器:

a) 打开Nginx默认站点配置:

sudo nano /etc/nginx/sites-available/default

b) 将以下内容添加到Nginx配置文件中:

server {
        listen        80;
        server_name   mydomain.com;

        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;
        }
}

c) 将"mydomain.com"替换为您的域名或IP地址。

  1. 重启Nginx:
sudo systemctl restart nginx
  1. 启动应用程序:

a) 转到应用程序发布目录:

cd bin/Release/net5.0/publish/

b) 启动应用程序(nohup 启动可以在断开终端时不影响程序运行):

nohup dotnet MyAspNetCoreApp.dll &
  1. 访问应用程序:

a) 在Web浏览器中输入您的IP地址或域名:

http://<server-ip-address-or-domain-name>

b) 您应该看到一个ASP.NET Core Web应用程序页面。

经过上述步骤后,您的ASP.NET Core应用程序应该已经部署并且可以通过 Nginx Web 服务器进行访问。

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表