先写部署
1. 前端部署
部署在winserver的nginx
1.1 下载nginx
已经放到了百度云和下载文件夹
地址:http://nginx.org/en/download.html
下一个稳定版,解压后运行nginx.exe即可,无需安装,浏览器访问:http://localhost 如果出现如下界面则表示nginx服务成功启动!
注意:
- 部署路径不要有中文字符
- 关闭iis,检查端口是否被占用,检查命令为
netstat -ano | findstr 0.0.0.0:80
- 仍然无法显示成功页面,查看nginx目录下logs里面的日志文件,然后百度
1.2 配置前端网站
在nginx的html文件夹下新建项目文件夹,名称自己取
然后修改 nginx/conf 文件夹下的 nginx.conf 一些没用的注释都删了,主要的节点就是两个location 的配置,注意 root 配置斜杠问题不要用"\“,用”/"
worker_processes 1;
events {
worker_connections 1024;
}
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8008;
server_name localhost;
# api 重写配置
location ^~ /api/ {
# 后端地址
proxy_pass http://10.236.254.154:8007/api/;
}
# 前端页面
location / {
root D:/nginx/html/wechat_web;
index index.html index.htm;
# 配置把所有匹配不到的路径重定向到index.html,vue-router的mode是history模式的情况下需要配置,否则会出现刷新页面404的情况
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
配置文件修改完成后重启Nginx,注意不要用语句重启,要在进程里关掉Nginx然后启动,不然更改配置文件不生效
Nginx常用命令
- 启动:
start nginx
或者直接nginx.exe
- 停止:
nginx.exe -s stop
或者nginx.exe -s quit
- 重启:
nginx.exe -s reload
2. 后端部署
2.1 打包
右击项目-发布-发布到文件夹
2.2 安装环境
下载地址:https://dotnet.microsoft.com/en-us/download/dotnet/6.0
要安装两个Hosting Bundle 和 Runtime
2.3 运行
复制打包好的文件到服务器 ,直接运行.exe文件即可