您的位置:首页 > 运维架构 > Nginx

.Net Core 2.0 + CentOS 7 + Nginx(编译发布)

2018-01-11 11:50 549 查看
发布篇:

CentOs 6.5 安装 MySql (本地测试,能用为主) 【传送门

CentOS 7 安装 .Net Core (CentOS 6.5太坑,放弃了)

CentOS 7 IP配置

ip a

查看网卡名称,对应修改(参考)

TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATA
IPV6INIT=no
IPV6_AUTOCONF=no
IPV6_DEFROUTE=no
IPV6_PEERDNS=no
IPV6_PEERROUTES=no
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
UUID=20bd5272-e84c-4893-867a-b854df14ec68
DEVICE=ens160
ONBOOT=yes
IPADDR0=192.168.1.210
NETMASK=255.255.255.0
PREFIX0=24
DNS1=233.5.5.5


安装 Dotnet

参考官方运行即可,一般不会有问题(需要CentOS网络)【官方传送门

dotnet --info

显示如下标示成功

.NET Command Line Tools (2.0.2)

Product Information:
Version:            2.0.2
Commit SHA-1 hash:  a04b4bf512

Runtime Environment:
OS Name:     centos
OS Version:  7
OS Platform: Linux
RID:         centos.7-x64
Base Path:   /usr/share/dotnet/sdk/2.0.2/

Microsoft .NET Core Shared Framework Host

Version  : 2.0.0
Build    : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d

发布

> cd /wwwwroot

> dotnet publish -r centos.7-x64
#Microsoft (R) Build Engine version 15.4.8.50001 for .NET Core
#Copyright (C) Microsoft Corporation. All rights reserved.

#  Bundler: Begin processing bundleconfig.json
#  Bundler: Done processing bundleconfig.json
#  Lsxx.Static -> /wwwroot/Lsxx.Static/bin/Debug/netcoreapp2.0/centos.7-x64/Lsxx.Static.dll
#  Lsxx.Static -> /wwwroot/Lsxx.Static/bin/Debug/netcoreapp2.0/centos.7-x64/publish/


运行

> cd /wwwroot/Lsxx.Static/bin/Debug/netcoreapp2.0/centos.7-x64/publish

> dotnet Lsxx.Static.dll

#info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
#      User profile is available. Using '/root/.aspnet/DataProtection-Keys' as key repository; #keys will not be encrypted at rest.
#Hosting environment: Production
#Content root path: /wwwroot/Lsxx.Static/bin/Debug/netcoreapp2.0/centos.7-x64
#Now listening on: http://localhost:5000 #Application started. Press Ctrl+C to shut down.


Nginx 安装(简易安装)

curl -o  nginx.rpm http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm 
rpm -ivh nginx.rpm

yum install nginx

安装成功!

systemctl start nginx #启动nginx

systemctl enable nginx #设置nginx的开机启动

配置Nginx

vi /etc/nginx/conf.d/default.conf

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

nginx –s reload #生效配置


防火墙

#关闭firewall:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动

firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)

#安装iptables

yum install iptables-services
vi /etc/sysconfig/iptables

# ...
# -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
# -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
# -A INPUT -p tcp -m state --state NEW -m tcp --dport 5000 -j ACCEPT
# ...

systemctl restart iptables.service #最后重启防火墙使配置生效

systemctl enable iptables.service #设置防火墙开机启动

#关闭SELINUX

vi /etc/selinux/config

#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加

setenforce 0 #使配置立即生效


谢谢

参考:
https://www.cnblogs.com/ants/p/5732337.html http://asp.net
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: