当前位置:首页 > 服务器技术 > nginx

linux安装nginx,设置代理,负载均衡

Linux安装nginx


首先下载:wget http://nginx.org/download/nginx-1.15.2.tar.gz

linux安装nginx,设置代理,负载均衡 - 文章图片

 

解压:tar -xvf nginx-1.15.2.tar.gz

  cd /usr/local/nginx-1.15.2

  .configure(此步会报错)

①:checking for C compiler … not found

  yum -y install gcc

  yum -y install gcc-c++

②:error: the HTTP rewrite module requires the PCRE library.

  You can either disable the module by using --without-http_rewrite_module
  option, or install the PCRE library into the system, or build the PCRE library
  statically from the source with nginx by using --with-pcre= option.

  yum -y install openssl openssl-devel

  

然后:

  make

  make install

  /usr/local/nginx-1.15.2/objs/nginx    或   /usr/local/nginx/nginx (启动)

  /usr/local/nginx/conf/nginx.conf  配置文件

  

  upstream wzz {
    server 127.0.0.1:8080 weight=8;   (weight: 数值越大 权重越高,down: 此服务器不参与轮询,backup   预留服务器(正式服务器挂了时,启动预留服务器))
    server 127.0.0.1:8888;
    server 127.0.0.1:9999;
  }

 

  location / {
    root html;
    index index.html index.htm;
    proxy_pass http://wzz;

    (可选项)
    proxy_set_header Host $host;

    proxy_set_header X-Real-IP $remote_addr;

    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }

  


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!