nginx安装、nginx前后端不分离、前后端分离配置、nginx location代理配置
Nginx部署.NET服务1、 下载SDK.NET8.0https://learn.microsoft.com/zh-cn/dotnet/core/install/linux-ubuntu-install?tabsdotnet8pivotsos-linux-ubuntu-2204JAVA自行网站查找暂无2、nginx下载sudoaptinstall-ynginx默认下载文件夹为/etc/nginx3、nginx.conf文件配置反向代理前后端不分离配置server{listen22110;# server_name 可配置为IP或域名 server_name localhost xxx.venny.cn;client_max_body_size 200m;location/{root/usr/share/nginx/html;index index.html;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connectionupgrade;# 可选配置,有请求转发需求时配置 #proxy_redirect http://源IP:源端口/http://目标IP:目标端口/;# 示例:#proxy_redirect http://127.0.0.1:80/http://127.0.0.1:8080/proxy_set_header Host $host:$proxy_port;#proxy_set_header Host $host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerREMOTE-HOST$remote_addr;proxy_set_headerX-Forwarded-For $proxy_add_x_forwarded_for;proxy_pass http://localhost:8080/;}}前后端分离配置server{listen80;# 多个域名用空格隔开 server_name 域名;#例如:map.venny.cn location/{proxy_set_header Host $host;root/web/front/;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerREMOTE-HOST$remote_addr;proxy_set_headerX-Forwarded-For $proxy_add_x_forwarded_for;try_files $uri $uri//index.html;index/index.html;}location/api/{proxy_set_header Host $host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerREMOTE-HOST$remote_addr;proxy_set_headerX-Forwarded-For $proxy_add_x_forwarded_for;add_header Access-Control-Allow-Methods*;add_header Access-Control-Allow-Origin $http_origin;proxy_pass http://127.0.0.1:8010/;}}4、配置完成重新加载nginx配置文件nginx -s reload nginx -t5、idea打包完成的部署文件进行服务器上传上传到打包文件到自定义文件夹这是/www/sfpj配置.net服务的软连接便于用systemctl控制服务在 /etc/systemd/system 文件下新建sfpj.service文件并编辑如下内容[Unit]Description.NET RUNNING API[Service]WorkingDirectory/www##部署的文件夹ExecStart/usr/bin/dotnet /www/SFPJ.dll##部署文件加dll文件RestartalwaysRestartSec10KillSignalSIGINTSyslogIdentifierdotnet-apiUserrootEnvironmentASPNETCORE_ENVIRONMENTProductionEnvironmentDOTNET_PRINT_TELEMETRY_MESSAGEfalse[Install]WantedBymulti-user.target重新加载systemdsystemctl daemon-reload启动服务systemctl start sfpj关闭服务systemctl stop sfpj查看服务状态这里是已经running了systemctl status sfpj查看页面访问是否可以正常显示浏览器敲服务器ip/域名端口可以访问就是成功了。