linux安装nginx,设置代理,负载均衡
Linux安装nginx
首先下载:wget http://nginx.org/download/nginx-1.15.2.tar.gz
解压: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 pcre-devel
③:./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library. You can either disable the module by using
--without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
--with-http_ssl_module --with-openssl=<path> options.
yum -y install openssl openssl-devel
然后:
make
make install
/xxx/nginx-1.15.2/objs/nginx 或 /xxx/nginx/nginx (启动)
/xxx/nginx/conf/nginx.conf 配置文件
upstream xxx{
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 C:/abc/zxc;
index index.html index.htm;
proxy_pass http://xxx;
(可选项)
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
nginx.conf 配置文件生效 /xxx/nginx/sbin/nginx -c /xxx/nginx/conf/nginx.conf