欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

centos 7 安装donet core2.0环境

程序员文章站 2024-03-11 09:43:56
...

安装环境: centOS 7.0

其他环境参照: https://www.microsoft.com/net/download/linux-package-manager/centos/sdk-current

Add the dotnet product feed

Before installing .NET, you’ll need to register the Microsoft key, register the product repository, and install required dependencies. This only needs to be done once per machine.

Open a command prompt and run the following commands:

sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm

Install the .NET SDK

sudo yum update
sudo yum install libunwind libicu
sudo yum install dotnet-sdk-2.1.200

创建Web应用

cd /usr/local/dotnetLearn
dotnet new razor -o aspnetcoreapp
cd aspnetcoreapp
dotnet run

站点已启动, 此时外面还不能访问,需要使用nginx做代理

安装ngxin

##安装依赖
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

yum install gcc gcc-c++


yum install nginx

修改配置文件
首先查看配置文件位置:

nginx -t

得到配置文件位置在:/etc/nginx/nginx.conf

修改配置文件, 添加反向代理.

upstream apachephp  {
#    server 127.0.0.1:5001; #Apache
 server 127.0.0.1:5000;
}
server {
       listen       80;
       location / {            
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;                       
        proxy_pass  http://apachephp;
           client_max_body_size    1000m; 
       }          
    }

启动nginx

systemctl start nginx
#把Nginx加到系统启动项
systemctl enable nginx

外部直接访问虚拟机80端口即可.