美文网首页
nginx 配置负载均衡

nginx 配置负载均衡

作者: _WhatsUp_ | 来源:发表于2022-11-03 01:34 被阅读0次

    【主服务器】

    upstream myserver {
            #把请求转发给连接数比较少的服务器
            least_conn;
            server 192.168.1.1:8080;
            server 192.168.1.2:8080;
        server 192.168.1.3:8080;
        }
        
    server {
        listen 80;
        server_name www.test.com;
    
        location / {
            proxy_pass http://myserver;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }
    
    
    server {
    
      listen 8080;
      listen 443;
      server_name  www.test.com;
      root /data/www.test.com;
      index index.php index.html;
      charset utf-8;
      
      access_log  /var/log/nginx/access_www.test.com.log;
      error_log  /var/log/nginx/error_www.test.com.log;
    
      location = /robots.txt { allow all; access_log off; log_not_found off; }
      location = /favicon.ico { allow all; access_log off; log_not_found off; }
    
      error_page 401 /401.html;
      error_page 403 /403.html;
      error_page 404 /404.html;
      error_page 500 502 503 504 /50x.html;
    
      location ~ .*\.(php|php5)?($|/)
      {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
      }
    
      location ~ /\.ht {
        deny  all;
      }
    
    }
    

    【从服务器】

    server {
    
      listen 8080;
      listen 443;
      server_name  www.test.com;
      root /data/www.test.com;
      index index.php index.html;
      charset utf-8;
      
      access_log  /var/log/nginx/access_www.test.com.log;
      error_log  /var/log/nginx/error_www.test.com.log;
    
      location = /robots.txt { allow all; access_log off; log_not_found off; }
      location = /favicon.ico { allow all; access_log off; log_not_found off; }
    
      error_page 401 /401.html;
      error_page 403 /403.html;
      error_page 404 /404.html;
      error_page 500 502 503 504 /50x.html;
    
      location ~ .*\.(php|php5)?($|/)
      {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
      }
    
      location ~ /\.ht {
        deny  all;
      }
    
    }
    

    相关文章

      网友评论

          本文标题:nginx 配置负载均衡

          本文链接:https://www.haomeiwen.com/subject/jfmstdtx.html