nginx+springboot项目的集群部署
(问题总结:1.使用docker的nginx在配置vue 的dist包时与正常的路径不一样所以下面的路径要修改为:location / {#这个是docker中nginx的路径,因为我们是做的配置文件映射,所以我们这里面配置的地址都要基于docker中的真实路径root/usr/share/nginx/html/dist;try...
(问题总结:
1.使用docker的nginx在配置vue 的dist包时与正常的路径不一样所以下面的路径要修改为:
location / {
#这个是docker中nginx的路径,因为我们是做的配置文件映射,所以我们这里面配置的地址都要基于docker中的真实路径
root /usr/share/nginx/html/dist;
try_files $uri $uri/ =404;
index index.html ;
}
2.集群部署时遇到了一个文件服务器的问题,因为当前项目文件的上传是与服务代码同体的,所以集群部署的话会出现无法下载文件的情况。
解:解决这个问题可以使用集群部署后台程序所在的服务器,实现磁盘共享,这样就可以实现文件的统一(可以在不同后台服务获取到公共的文件资源)
)
本次集群部署的方案:
1.为了提高信息集成平台的并发能力,
2.为了提高平台高可用性
集群方案:
https://www.cnblogs.com/royal6/p/12149852.html
实现记录:
(压力测试优化)
本次负载均衡的策略是:
ip_hash
指定负载均衡器按照基于客户端IP的分配方式,这个方法确保了相同的客户端的请求一直发送到相同的服务器,以保证session会话。这样每个访客都固定访问一个后端服务器,可以解决session不能跨服务器的问题。
(使用该策略可以水平服务并发处理的能力,并保证原有websocket长连接的正确使用)
原配置文件:
user root;
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 200;
client_header_timeout 120s; #调大点
client_body_timeout 120s; #调大点
client_max_body_size 100m; #主要是这个参数,限制了上传文件大大小
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
gzip on;
gzip_buffers 4 16k;
gzip_comp_level 5;
gzip_types text/plain application/javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
server {
listen 80;
server_name 106.54.140.88;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html/dist;
try_files $uri $uri/ /index.html;
index index.html ;
}
location /websocket {
proxy_pass http://106.54.140.88:8899/websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /ssoLogin {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://106.54.140.88:8899/ssoLogin;
}
location /xboot {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://106.54.140.88:8899/xboot;
}
location /loginTest {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://106.54.140.88:8899/loginTest;
}
location /hnPortalApp {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://106.54.140.88:8899/hnPortalApp;
}
location /qrcode {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://106.54.140.88:8899/qrcode;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
#测试转发单点接口
server {
listen 9797;
server_name 10.39.5.120;
location /portal/sso {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://10.39.5.120:9797/portal/sso;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
实现集群后的配置文件:
user root;
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 200;
client_header_timeout 120s; #调大点
client_body_timeout 120s; #调大点
client_max_body_size 100m; #主要是这个参数,限制了上传文件大大小
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
gzip on;
gzip_buffers 4 16k;
gzip_comp_level 5;
gzip_types text/plain application/javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html/dist;
try_files $uri $uri/ /index.html;
index index.html ;
}
location /websocket {
proxy_pass http://server_list/websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /ssoLogin {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://server_list/ssoLogin;
}
location /xboot {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://server_list/xboot;
}
location /loginTest {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://server_list/loginTest;
}
location /hnPortalApp {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://server_list;
}
location /qrcode {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://server_list;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
upstream server_list{
ip_hash;
server 106.54.140.88:8899 weight=5;
server 47.92.27.141:8899 weight=5;
}
}
更多推荐
所有评论(0)