iis服务器助手广告
返回顶部
首页 > 资讯 > 后端开发 > PHP编程 >PHP项目临时拓容Nginx负载均衡实操记录
  • 768
分享到

PHP项目临时拓容Nginx负载均衡实操记录

nginx负载均衡php 2023-09-01 14:09:16 768人浏览 八月长安
摘要

项目域名:test.baidu.com 服务器A:127.0.0.1 //内网ip(原有服务器) 服务器B:172.30.228.254//内网ip 需求:项目本在服务器A中正常运行,现在临时搞活动,

项目域名:test.baidu.com
服务器A:127.0.0.1 //内网ip(原有服务器)
服务器B:172.30.228.254//内网ip

需求:项目本在服务器A中正常运行,现在临时搞活动,需要拓容一台/多台服务器,在最小成本跟改动下完成

架构设计:把原有的A服务器昨晚负载均衡器,同时也作为其中一个项目服务,另外在购买一台服务器作为临时服务;原有服务器nginx 80端口变为负载均衡器端口,另设端口为项目服务

Nginx配置:
服务器A:

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;events    {        use epoll;        worker_connections 51200;        multi_accept on;    }Http    {        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;        limit_req_zone $binary_remote_addr zone=perip_req:10m rate=10r/s; #负载均衡upstream btsaas_balance {        server 127.0.0.1:8188 weight=100; #本地服务,端口不能是80,建议所有服务器端口统一,均不要80        server 172.30.228.254:8188 weight=100; #远端服务    }        #负载均衡主入口    server {listen       80; #主入口server_name  test.baidu.com; #监控项目对应域名#access_log  /PHP/host.access.log  main;location / {  proxy_redirect off;  proxy_set_header Host $host;  proxy_set_header X-Real_IP $remote_addr;  proxy_set_header X-Forwarded-For $remote_addr:$remote_port;  proxy_http_version 1.1;  proxy_set_header Upgrade $http_upgrade;   # 升级协议头  proxy_set_header Connection upgrade;  proxy_set_header X-FORWARDED-PROTO $scheme ;  #负载均衡转发 proxy_pass http://btsaas_balance; }}#本地项目服务,不能再监听80,应选另外端口,跟常规nginx项目配置一样server{listen 8188;server_name test.baidu.com; #这里监控项目域名index index.php index.html index.htm default.php default.htm default.html;root /home/wwwroot/test; #项目根目录#PHP-INFO-START  PHP引用配置,可以注释或修改include enable-php-72.conf;#PHP-INFO-END#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效include /www/server/panel/vhost/rewrite/test.conf;#REWRITE-END#phplocation ~ \.php$ {#限流 访问php的 同一ip 并发链接20以内limit_conn perip 30;#同一ip限制速度10个每秒 缓冲池为10limit_req zone=perip_req burst=500 nodelay;   }#禁止访问的文件或目录location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md){return 404;}#一键申请SSL证书验证目录相关设置location ~ \.well-known{allow all;}location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)${expires      30d;error_log off;access_log /dev/null;}location ~ .*\.(js|css)?${expires      12h;error_log off;access_log /dev/null; }}}

临时服务器B Nginx 配置跟A一样,但只需要监控8188端口server,负载均衡那部分去掉即可

**注意:
1:session 处理;
2:微信授权token处理;
3:proxy_set_header 设置请求头必须要x-x-x 不能用下划线x_x_x
4:注意项目内的.user.ini里面指定了PHP中的basedir,必须保证跟项目根目录文件一致
**

来源地址:https://blog.csdn.net/lqb3732842/article/details/128836537

--结束END--

本文标题: PHP项目临时拓容Nginx负载均衡实操记录

本文链接: https://www.lsjlt.com/news/388626.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作