前置工作
安装宝塔,MYSQL,FTP等软件
宝塔官网
yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh
目录
安装.netcore 6.0 SDK
# 添加微软官方源
rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
# 安装SDK
yum -y install dotnet-sdk-6.0
# 验证安装是否成功
dotnet --info
https 无法访问,可能是443端口未开放
#查看端口开放情况
firewall-cmd --zone=public --list-ports
#开放443/80端口
firewall-cmd --zone=public --add-port=443/tcp --permanent
#重启防火墙
firewall-cmd --reload
配置Supervisor守护进程
安装supervisor
yum -y install supervisor
#启动服务
supervisord -c /etc/supervisord.conf
进入etc/supervisord.d文件夹创建 xxx.ini文件
[program:项目名称]
command=dotnet 项目名称.dll
directory=/www/wwwroot/网站根目录
autostart=true
autorestart=true
startretries=5
startsecs=1
user=root
priority=999
stderr_logfile=/var/log/AbpMPA.err.log
stdout_logfile=/var/log/AbpMPA.out.log
environment=ASPNETCORE_ENVIRONMENT=Production
stopsignal=INT
刷新supervisord配置
supervisorctl reload
查看supervisorctl守护项目状态
supervisorctl
.
配置Nginx反向代理
无SSL证书配置
server
{
listen 80;
server_name 网址;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/网站根目录;
#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#error_page 404/404.html;
#SSL-END
#ERROR-PAGE-START 错误页配置,可以注释、删除或修改
#error_page 404 /404.html;
#error_page 502 /502.html;
#ERROR-PAGE-END
#PHP-INFO-START PHP引用配置,可以注释或修改
include enable-php-00.conf;
#PHP-INFO-END
#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
include /www/server/panel/vhost/rewrite/对应文件名.conf;
#REWRITE-END
location / {
proxy_pass http://localhost:5000; #把80端口的访问反向代理到5000端口(你程序的启动端口),请根据实际情况修改自己的端口
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 客户端真实ip
proxy_set_header X-Real-IP $remote_addr;
}
#禁止访问的文件或目录
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
{
return 404;
}
#一键申请SSL证书验证目录相关设置
location ~ \.well-known{
allow all;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
proxy_pass http://127.0.0.1:5000;
expires 30d;
error_log off;
access_log /dev/null;
}
location ~ .*\.(js|css)?$
{
proxy_pass http://127.0.0.1:5000;
expires 12h;
error_log off;
access_log /dev/null;
}
access_log /www/wwwlogs/网址.log;
error_log /www/wwwlogs/网址.error.log;
}
带SSL证书配置
# 实际websocket服务器地址
upstream wss_svr {
server 127.0.0.1:39241 weight=1;
}
# http指向https
server {
listen 80;
server_name 域名;
rewrite ^(.*)$ https://${server_name}$1 permanent;
}
server
{
listen 443 ssl;
server_name 域名;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/项目目录;
ssl_certificate /www/wwwroot/项目目录/SSL/xxx.crt;
ssl_certificate_key /www/wwwroot/项目目录/SSL/xxx.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#error_page 404/404.html;
#SSL-END
#ERROR-PAGE-START 错误页配置,可以注释、删除或修改
#error_page 404 /404.html;
#error_page 502 /502.html;
#ERROR-PAGE-END
#PHP-INFO-START PHP引用配置,可以注释或修改
include enable-php-56.conf;
#PHP-INFO-END
#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
include /www/server/panel/vhost/rewrite/配置文件.conf;
#REWRITE-END
location / {
proxy_pass http://localhost:5000; #把80端口的访问反向代理到5000端口(你程序的启动端口),请根据实际情况修改自己的端口
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 客户端真实ip
proxy_set_header X-Real-IP $remote_addr;
}
location /wss {
proxy_redirect off;
proxy_pass http://wss_svr; # 转发
proxy_set_header Host $host;
proxy_set_header X-Real_IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr:$remote_port;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; # 升级协议头
proxy_set_header Connection upgrade;
}
#禁止访问的文件或目录
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
{
return 404;
}
#一键申请SSL证书验证目录相关设置
location ~ \.well-known{
allow all;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
proxy_pass http://127.0.0.1:5000;
expires 30d;
error_log off;
access_log /dev/null;
}
location ~ .*\.(js|css)?$
{
proxy_pass http://127.0.0.1:5000;
expires 12h;
error_log off;
access_log /dev/null;
}
access_log /www/wwwlogs/项目名称.log;
error_log /www/wwwlogs/项目名称.error.log;
}
重启nginx
nginx -s reload
运行.netcore项目
cd进入网站根目录
dotnet 项目名称.dll
#显示以下内容即成功运行
Hosting environment: Production
Content root path: 网站根目录
Now listening on: http://localhost:5000
Now listening on: http://localhost:5001
Application started. Press Ctrl+C to shut down.