编程技术分享平台

网站首页 > 技术教程 正文

nginx项目部署与反向代理、负载均衡

xnh888 2024-10-14 19:55:35 技术教程 22 ℃ 0 评论

vue项目打包

执行命令,生成dist文件

npm run build

把dist文件复制到指定的目录,如:

Springboot项目api打包

  1. 项目目录结构
  1. 打包准备工作

Pom.xml中加入一下配置

<build>
<
plugins>
<
plugin>
<
groupId>org.springframework.boot</groupId>
<
artifactId>spring-boot-maven-plugin</artifactId>
</
plugin>
</
plugins>
</
build>

  1. 执行打包命令
  1. 复制生成的jar到指定的目录

Nginx配置

1.nginx.conf

#user nobody;

worker_processes 1;

#pid logs/nginx.pid;

events {

worker_connections 1024;

}

http {

include mime.types;

default_type application/octet-stream;

sendfile on;

#tcp_nopush on;

#keepalive_timeout 0;

keepalive_timeout 65;

#gzip on;

#vue 前端项目

server {

listen 80;

server_name localhost;

location / {

root D:/2007B/dist/;

try_files $uri $uri/ /index.html;

}

}

#springboot-后端项目

upstream myserver{

#ip_hash;

server 127.0.0.1:9091 weight=5;

server 127.0.0.1:9092 weight=2;

server 127.0.0.1:9093 weight=1;

}

#nginx监听vue调用后端端口

server {

listen 9999;

server_name localhost;

location / {

proxy_pass http://myserver;

}

}

}

使用命令启动springBoot项目


启动9091端口

启动9092端口

启动9093端口

启动nginx服务

配置本地host域名访问

浏览器测试访问

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表