nginx搭建分布式简单配置

一、安装nginx

           安装nginx

    概要

安装编译工具及库文件
yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel
下载解压缩 nginx  pcre
tar zxvf pcre-8.43.tar.gz 
查看pcre版本
rpm -qa pcre
查看pcre安装目录
rpm -ql pcre
配置
 ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=/**/src/ --with-pcre=/usr/local/soft/pcre-8.43
编译
make && make install
nginx 版本查看
/usr/local/webserver/nginx/sbin/nginx -v
启动
/usr/local/webserver/nginx/sbin/nginx
重启
/usr/local/webserver/nginx/sbin/nginx -s reload
关闭
/usr/local/webserver/nginx/sbin/nginx -s stop

二、编写配置文件 nginx.conf

worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

 upstream test {  
      #根据ip计算将请求分配各那个后端tomcat,许多人误认为可以解决session问题,其实并不能。  
      #同一机器在多网情况下,路由切换,ip可能不同  
      #ip_hash;   
      server ****:8180;
      server ****:8180;
    }


    server {
            listen       8180;
            server_name  test;

            #对aspx后缀的进行负载均衡请求
        location / {
          proxy_connect_timeout 3;  
          proxy_send_timeout 30;  
          proxy_read_timeout 30;  
          proxy_pass http://test/;  #对应upstream
                  
        }

        add_header X-Via $server_addr;
        add_header X_cache_hit $upstream_cache_status;
    }
}

三、启动ngnix(指定配置文件)

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

 四、关闭重启

/usr/local/nginx/sbin/nginx -s reload
/usr/local/nginx/sbin/nginx -s stop

 

posted @ 2018-11-13 16:22  阿衰问问  阅读(870)  评论(0编辑  收藏  举报