一、net7.0环境搭建
二、安装配置nginx
1、安装nginx
sudo yum install yum-utils
sudo dnf install nginx
2、启动nginx(需要先确保80端口未被其他程序占用)
systemctl start nginx
3、设为开机启动
systemctl enable nginx
4、查看版本
nginx -v
5、配置nginx文件,覆盖nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
client_max_body_size 500m;
server {
listen 80;
server_name _;
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;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
}
}
}
6、验证配置
sudo nginx -t
7、重载
sudo nginx -s reload
三、创建服务
以sscms系统为例
创建服务定义文件 sscms.servic
sudo touch /etc/systemd/system/sscms.service
将以下内容保存至 /etc/systemd/system/sscms.service:
[Unit]
Description=SSCMS
[Service]
WorkingDirectory=/var/www
ExecStart=/usr/bin/dotnet /var/www/SSCMS.Web.dll
Restart=always
#Restart service after 10 seconds if the sscms service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=sscms
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
保存文件并启用服务。
sudo systemctl enable sscms.service
运行服务,并确认它正在运行。
sudo systemctl start sscms.service
sudo systemctl status sscms.service