遇到的问题 一开始 写了2个ip 发现始终只能走其中的一个 最后才发现 原来配置负载均衡的服务器 不能自己再提供服务了 所以- -
想要负载均衡一般来说 需要3台机器 第一台 是做代理的 再提供另外2个服务器配置就可以了
fuzai1 做提供服务 代码如下
ip_hash 则这样写
upstream web1{
#ip_hash;
server 192.168.0.203;
server 192.168.0.204;
}
否则如下
http里增加下面这个
upstream web1{
server 192.168.0.203 weight=1;
server 192.168.0.204 weight=1;
}
server里增加
location /{
index index.php index.html index.htm;
root /home/wwwroot/default;
proxy_pass http://web1;
proxy_set_header Host $host;
}
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128;
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;
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 application/xml+rss;
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;
##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.
server_tokens off;
access_log off;
upstream web1{
server 192.168.0.203 weight=1;
server 192.168.0.204 weight=1;
}
server
{
listen 80;
#listen [::]:80 default_server ipv6only=on;
server_name www.fk1.com;
#index index.php index.html index.htm;
#root /home/wwwroot/default;
location /{
index index.php index.html index.htm;
root /home/wwwroot/default;
proxy_pass http://web1;
proxy_set_header Host $host;
}
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
include enable-php.conf;
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log /home/wwwlogs/access.log;
}
include vhost/*.conf;
}
虚拟域名配置
[root@localhost conf]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.0.202 www.fk1.com
192.168.0.203 www.fk2.com
192.168.0.204 www.fk3.com
fuzai1的 ip为192.168.0.202
fuzai2的ip为192.168.0.203
fuzai3的ip为 192.168.0.204
接下来每次请求 192.168.0.202
请求虚拟域名也行
这个是ip轮询的方式 为了session 图片啥的奇葩问题 可以写成ip_hash 这样 这是最基本的负载均衡配置
后面未来还会涉及到 文件同步等等 这些问题。。。。