宝塔nginx配置SpringBoot服务集群代理

news/2024/4/25 8:17:39

宝塔nginx配置SpringBoot服务集群代理

1、需求:

现有一个springboot服务需要部署成集群,通过nginx负载均衡进行访问,其中这个springboot服务内置了MQTT服务、HTTP服务、TCP服务。

MQTT服务开放了1889端口

HTTP服务开放了8891端口

HTTP服务开放了8893端口

TCP服务开放了8893端口

该服务在宝塔部署启动后开启的端口

在这里插入图片描述

2、nginx代理部署后的集群服务

宝塔nginx的nginx.conf位置

/www/server/nginx/conf/nginx.conf

nginx.conf原始内容:

user  www www;
worker_processes auto;
error_log  /www/wwwlogs/nginx_error.log  crit;
pid        /www/server/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;stream {log_format tcp_format '$time_local|$remote_addr|$protocol|$status|$bytes_sent|$bytes_received|$session_time|$upstream_addr|$upstream_bytes_sent|$upstream_bytes_received|$upstream_connect_time';access_log /www/wwwlogs/tcp-access.log tcp_format;error_log /www/wwwlogs/tcp-error.log;include /www/server/panel/vhost/nginx/tcp/*.conf;
}events{use epoll;worker_connections 51200;multi_accept on;}http{include       mime.types;#include luawaf.conf;include proxy.conf;default_type  application/octet-stream;server_names_hash_bucket_size 512;client_header_buffer_size 32k;large_client_header_buffers 4 32k;client_max_body_size 50m;sendfile   on;tcp_nopush on;keepalive_timeout 60;tcp_nodelay on;fastcgi_connect_timeout 300;fastcgi_send_timeout 300;fastcgi_read_timeout 300;fastcgi_buffer_size 64k;fastcgi_buffers 4 64k;fastcgi_busy_buffers_size 128k;fastcgi_temp_file_write_size 256k;fastcgi_intercept_errors on;gzip on;gzip_min_length  1k;gzip_buffers     4 16k;gzip_http_version 1.1;gzip_comp_level 2;gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml;gzip_vary on;gzip_proxied   expired no-cache no-store private auth;gzip_disable   "MSIE [1-6]\.";limit_conn_zone $binary_remote_addr zone=perip:10m;limit_conn_zone $server_name zone=perserver:10m;server_tokens off;access_log off;server{listen 888;server_name phpmyadmin;index index.html index.htm index.php;root  /www/server/phpmyadmin;#error_page   404   /404.html;include enable-php.conf;location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)${expires      30d;}location ~ .*\.(js|css)?${expires      12h;}location ~ /\.{deny all;}access_log  /www/wwwlogs/access.log;}
include /www/server/panel/vhost/nginx/*.conf;
}

文件中的 include /www/server/panel/vhost/nginx/tcp/*.conf;表明了nginx加载.conf文件的位置,我们要配置集群代理,需要

在/www/server/panel/vhost/nginx/这个目录下面配置多个.conf文件,即可完成需求。

在这里插入图片描述

a、修改java_veiplinks-standalone.conf

upstream iotserver {server 192.168.0.26:8844;server 192.168.0.27:8844;server 192.168.0.28:8844;server 192.168.0.107:8848;server 192.168.0.104:8848;
}upstream fileserver {
#  server 192.168.0.26:8844; #此处指定文件上传到该服务器上server 192.168.0.107:8848;
}server {listen       80;server_name  iot_server # gzip configgzip on;gzip_min_length 1k;gzip_comp_level 9;gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;gzip_vary on;gzip_disable "MSIE [1-6]\.";root /home/wwwroot/iotlinks-client/dist;
#     include /etc/nginx/mime.types;location / {index  index.html;}location ^~/upload/ {proxy_pass http://fileserver;proxy_set_header Host $host:$server_port;proxy_set_header X-Real-IP  $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}location ^~/veiplinks/file/static {proxy_pass http://fileserver/file/static;proxy_set_header X-Forwarded-Proto $scheme;proxy_set_header Host $host:$server_port;proxy_set_header X-Real-IP  $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_send_timeout      30m;proxy_read_timeout      30m;client_max_body_size    100m;}location ^~/veiplinks/ {proxy_pass http://iotserver/;proxy_set_header X-Forwarded-Proto $scheme;proxy_set_header Host $host:$server_port;proxy_set_header X-Real-IP  $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";proxy_connect_timeout   1;proxy_buffering off;chunked_transfer_encoding off;proxy_cache off;proxy_send_timeout      30m;proxy_read_timeout      30m;client_max_body_size    100m;}
}

b、在tcp目录下创建文件ngx_stream_proxy.conf并编辑

   upstream mqtt-cluster {
#        hash $remote_addr consistent;server 192.168.0.26:1889 max_fails=3 fail_timeout=10s;server 192.168.0.27:1889 max_fails=3 fail_timeout=10s;server 192.168.0.28:1889 max_fails=3 fail_timeout=10s;server 192.168.0.107:1889 max_fails=3 fail_timeout=10s;server 192.168.0.104:1889 max_fails=3 fail_timeout=10s;}upstream http-cluster {
#        hash $remote_addr consistent;server 192.168.0.26:8891 max_fails=3 fail_timeout=10s;server 192.168.0.27:8891 max_fails=3 fail_timeout=10s;server 192.168.0.28:8891 max_fails=3 fail_timeout=10s;server 192.168.0.107:8891 max_fails=3 fail_timeout=10s;server 192.168.0.104:8891 max_fails=3 fail_timeout=10s;}upstream tcp-cluster {
#        hash $remote_addr consistent;server 192.168.0.26:8893 max_fails=3 fail_timeout=10s;server 192.168.0.27:8893 max_fails=3 fail_timeout=10s;server 192.168.0.28:8893 max_fails=3 fail_timeout=10s;server 192.168.0.107:8893 max_fails=3 fail_timeout=10s;server 192.168.0.104:8893 max_fails=3 fail_timeout=10s;}upstream rs485-tcp-cluster {
#        hash $remote_addr consistent;server 192.168.0.26:8894 max_fails=3 fail_timeout=10s;server 192.168.0.27:8894 max_fails=3 fail_timeout=10s;server 192.168.0.28:8894 max_fails=3 fail_timeout=10s;server 192.168.0.107:8894 max_fails=3 fail_timeout=10s;server 192.168.0.104:8894 max_fails=3 fail_timeout=10s;}server {listen 1884;proxy_pass mqtt-cluster;proxy_connect_timeout 30s;proxy_timeout 30s;}server {listen 8841;proxy_pass http-cluster;proxy_connect_timeout 30s;proxy_timeout 30s;}server {listen 8843;proxy_pass tcp-cluster;proxy_connect_timeout 30s;proxy_timeout 30s;}server {listen 8844;proxy_pass rs485-tcp-cluster;proxy_connect_timeout 30s;proxy_timeout 30s;}

3、重启ngnix服务器,当请求来到nginx服务会被转发到不同服务器上


https://www.xjx100.cn/news/3280722.html

相关文章

[极客大挑战2019]upload

该题考点&#xff1a;后缀黑名单文件内容过滤php木马的几种书写方法 phtml可以解析php代码&#xff1b;<script language"php">eval($_POST[cmd]);</script> 犯蠢的点儿&#xff1a;利用html、php空格和php.不解析<script language"php"&…

线阵相机参数介绍---变频参数控制

变频器介绍 变频器功能的目的在于对外部输入信号进行运算处理&#xff0c;以达到理想的行频值。该功能主要是为了解决信号超行频&#xff0c;图像拉伸压缩等问题。 输入信号处理过程&#xff1a; 输入信号&#xff1a;允许出发相机信号的频率f与所要求输入信号的频率F不同 …

MySQL 学习记录 1

原文&#xff1a;https://blog.iyatt.com/?p12631 1 前言 去年年初报考 3 月的计算机二级&#xff08;C 语言&#xff09;【https://blog.iyatt.com/?p9266 】考过了&#xff0c;这次打算报考 3 月的计算机三级&#xff08;数据库&#xff09;。数据库这一块&#xff0c;很…

NPM运行保存问题解决

问题描述 我在控制台运行如下命令 npm run dev结果报出如下错误 > form-generator0.2.0 dev > vue-cli-service serveINFO Starting development server... 10% building 4/4 modules 0 active(node:4920) [DEP0111] DeprecationWarning: Access to process.binding(…

在哪些领域中最需要使用 OCR 识别技术?真实场景介绍

根据我们的项目经验总结来说&#xff0c;OCR&#xff08;光学字符识别&#xff09;技术在多个领域中扮演着至关重要的角色&#xff0c;它能够将图像中的文本内容转换为机器可读的格式&#xff0c;极大地提高了数据处理的效率和准确性。以下是一些主要领域及其对应的应用场景和用…

linux部署jenkins,支持jdk1.8

无废话&#xff0c;纯干活安装指令 本文前提条件需安装jdk8&#xff0c;安装参考&#xff1a;Linux配置jdk环境 下载资源 # 创建安装目录 mkdir -p /data/jenkins && cd /data/jenkins# 下载jenkins的war包&#xff0c;v2.346.x支持jdk1.8&#xff0c;高于这个版本的…

域名 SSL 证书信息解析 API 数据接口

域名 SSL 证书信息解析 API 数据接口 网络工具&#xff0c;提供域名 SSL 证书信息解析&#xff0c;多信息查询&#xff0c;毫秒级响应。 1. 产品功能 提供域名 SSL 证书信息解析&#xff1b;最完整 SSL 属性信息解析&#xff1b;支持多种元素信息抽取&#xff0c;包括主题的可…

GO框架基础 (三)、xorm库

xorm介绍 官网&#xff1a;https://xorm.io/ git文档&#xff1a;https://github.com/go-xorm/xorm xorm 是一个 Go 语言的 ORM&#xff08;对象关系映射&#xff09;库&#xff0c;它提供了一种简单、高效的方式来将 Go 语言中的结构体与数据库表进行映射&#xff0c;并提供了…