nginx静态资源转发及负载均衡部署

1.静态资源转发。

修改nginx配置文件,
server {
        listen       8765;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        
        location / {
        // root 静态资源文件存放位置
        // !-e $request_filename 当访问路径不存在该资源时,转发到本机8863 swoole端口
            root   /home/work/chat/static;
            index  index.html index.htm;
            if (!-e $request_filename) {
                proxy_pass http://127.0.0.1:8863;
            }

        }
}

2.nginx 负载均衡配置

  #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;
//新增 weight增加转发到该服务器的权重
upstream swoole_http {
	server 127.0.0.1 weight=2;  
	server 156.2.3.1 weight=1;
}
//新增
    server {
        listen       8765;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /home/work/chat/static;
            index  index.html index.htm;
            if (!-e $request_filename) {
            	//新增转发到 swoole_http 服务器上
                proxy_pass http://swoole_http;
            }

        }

你可能感兴趣的:(Nginx)