本次项目工程分为一台nginx主机和两台运行
Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器。因此首先需要先下载,具体地址如下 http://nginx.org/en/download.html 下载之后解压,打开conf文件夹然后编辑nginx.conf文件,本次demo具体的设置
upstream springBoot { # 你的serverIP地址 server 192.168.1.101:8081 weight=1; server 192.168.1.99:8081 weight=1; } server { listen 8081; server_name 8080.max.com; #charset koi8-r; #access_log logs/host.access.log main; location / { proxy_pass http://springBoot; index index.html index.htm; } }切记要放在http下面的大括号内容。
之后切换到nignx解压目录下面,运行命令start nginx,之后去logs文件夹下面看是否有包含pid字母的文件,这个文件后续用于nginx关闭,代表nginx正常启动。如果没有相关pid文件就看一下error.log文件是否有相关错误信息病解决。
SpringBoot程序已经打包,这里仅展示运行过程,具体代码末尾会附上。切换到安装包存放的路径,运行java -jar NginxSpringBoot-1.0-SNAPSHOT.jar,然后就可以访问主机的地址http://localhost:8081/hello, 多次刷新显示不一样的IP信息
案例地址:https://github.com/charmerares/Spring-Introduction/tree/master/SpringBoot_Nginx