linux centos7 和 windows下 部署 .net core 2.0 web应用

时间:2023-12-27 17:40:07

centos7 下部署asp.net core 2.0应用

  • 安装CentOS7
  • 配置网络【可选】
  • 安装.Net core2.0
  • 创建测试Asp.net Core应用程序
  • 正式部署项目

安装VMware->新建虚拟机->找到系统镜像->一步一步往下装,不多说了。。

如果ping baidu.com ping不通, 系统版本可能没有配置网络

博客园有很多CentOs配置网络的文章自己去搜索一下。。

安装.Net core2.0,创建测试Asp.net Core应用程序:

按照官网来就行,不再赘述:

https://www.microsoft.com/net/learn/get-started/linux/rhel#install

正式部署项目:

查看主机IP

使用FTP上传程序包到Linux

打开终端->找到项目根目录->执行 dotnet xxx.web.dll ,这个xxx.web.dll是指你的web应用程序集。

linux centos7 和 windows下 部署 .net core 2.0 web应用

搞定!

使用:IP+端口访问去吧。

部署之Docker

待续....

Windows下部署asp.net core 2.0 之  Kestrel

如果没有运行环境,请去下载: https://www.microsoft.com/net/learn/get-started/windows

打开cmd,使用cd /d c:\xxxpatn 命令 找到发布的项目根目录;运行dotnet xxx.web.dll,这个xxx.web.dll是指你的web应用程序集。

没有问题的话看下面

linux centos7 和 windows下 部署 .net core 2.0 web应用

本地访问:http://localhost:5000

使用Nginx反向代理服务器映射端口到80:

下载:http://nginx.org/en/download.html  安装

配置  \conf\nginx.conf 文件

 #user  nobody;
worker_processes 1; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections 1024;
} http {
include mime.types;
default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout 65; #gzip on;
#配置服务器地址,可以有多台,localhost 为 服务名
upstream localhost {
server 127.0.0.1:5000 weight=1;
} server {
       #侦听80端口
listen 80;
       #服务名称必须和upstream后面的名称一致
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; #location / {
# root html;
# index index.html index.htm;
#}
#指定访问时转发到哪里,localhost为服务名
location / {
proxy_pass http://localhost;
} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost; # ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#} }

配置好之后:我们cmd->cd /d Nginx目录->start nginx

访问 http://localhost 搞定!

Nginx其他命令:nginx -s stop 停止

Windows下部署asp.net core 2.0 之  IIS

待续....

Nginx 请求分发

待续....