前端vue项目打包成dist上传到服务器
后端springboot项目打包成jar上传到服务器
之后
下载nginx,把nginx.conf进行配置
单机部署
user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80; #前端被访问的地址
server_name localhost;
location / {
root /usr/local/project/springboot/ruoyi/dist; #前端dist路径
index index.html index.htm;
}
location /prod-api/ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://120.26.177.51:8080/; #反向代理的后端服务器地址
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
nginx启动
去sbin目录下
./nginx 为启动命令
========================================
集群模式
user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream ruoyi{
server 120.26.177.51:8080 weight=1;
server 120.26.177.51:8081 weight=2; #weight为权重
}
server {
listen 80; #前端被访问的地址
server_name localhost;
location / {
root /usr/local/project/springboot/ruoyi/dist; #前端dist路径
index index.html index.htm;
}
location /prod-api/ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://ruoyi/; #反向代理的后端服务器地址
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
参考资料
https://www.bilibili.com/video/BV1uK411p7Bp?from=search&seid=17786633873750424939