2023-11-14nginx配置反向代理和负载均衡

2023-11-13  本文已影响0人  原来是红灯啊

1,先配置的是不带http的反向代理,https的后面写
2、nginx下的nginx.conf文件
3、服务器组一定要在server外面

这是服务器组 weight是权重 ip_hash是策略,根据ip分配到那个服务器,有三种 
1、ip_hash
2、hash $request_rui
3、hash $cookie_jsessionid 这个是java的
   upstream backend{
        ip_hash;
            server 175.178.214.236:8081 weight=1;
            server 101.43.218.49:8081 weight=1;
            
        }


server
    {
        listen 80;
        server_name 101.43.218.49 yiyitian.com www.yiyitian.com localhost 127.0.0.1 api.yiyitian.com;
        index index.html index.htm index.php;
        root  /www/server/phpmyadmin;
            location ~ /tmp/ {
                return 403;
            }

这个地方是反向代理的
backend自定义的,但是要和上面一样
        location /{
            proxy_pass http://backend;
        }

        #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;
    }
上一篇 下一篇

猜你喜欢

热点阅读