Nginx服务器安装及负载均衡

yum install -y gcc-c++

[root@a opt]# vim nginx-library.sh下添加
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel

安装所需库
chmod 755 nginx-library.sh 使其有可执行权限-x
./nginx-library.sh

编译和安装
上传Nginx
tar -zxvf 解压

执行以下文件设置路径,进入设置makefile文件
[root@a nginx-1.8.0]# ./configure \

./configure \

–prefix=/usr/local/nginx
–pid-path=/var/run/nginx/nginx.pid
–lock-path=/var/lock/nginx.lock
–error-log-path=/var/log/nginx/error.log
–http-log-path=/var/log/nginx/access.log
–with-http_gzip_static_module
–http-client-body-temp-path=/var/temp/nginx/client
–http-proxy-temp-path=/var/temp/nginx/proxy
–http-fastcgi-temp-path=/var/temp/nginx/fastcgi
–http-uwsgi-temp-path=/var/temp/nginx/uwsgi
–http-scgi-temp-path=/var/temp/nginx/scgi

拍快照
make 编译
make install 安装

[root@a nginx-1.8.0]# cd /usr/local/nginx
[root@a nginx]# cd conf
[root@a conf]# vim nginx.conf

新窗口
[root@a ~]# cd /usr/local/nginx/
[root@a nginx]# mkdir logs

存放日志信息的路径
9 error_log /usr/local/nginx/logs/error.log;
10
11 #pid logs/nginx.pid;
12
13 pid /usr/local/nginx/logs/nginx.pid;

24 log_format main '$remote_addr - r e m o t e u s e r [ remote_user [ remoteuser[time_local] “ r e q u e s t " ′ 2 5 ′ request" ' 25 ' request"25status b o d y b y t e s s e n t " body_bytes_sent " bodybytessent"http_referer” ’
26 ‘“ h t t p u s e r a g e n t " " http_user_agent" " httpuseragent""http_x_forwarded_for”’;
27
28 #access_log logs/access.log main;
29 access_log /usr/local/nginx/logs/access.log main;

启动
[root@a nginx]# cd sbin
[root@a sbin]# ./nginx
nginx: [emerg] mkdir() “/var/temp/nginx/client” failed (2: No such file or directory)

mkdir -p /var/temp/nginx/client
[root@a sbin]# ./nginx

[root@a nginx]# cat ./logs/error.log
[root@a nginx]# cat ./logs/access.log

ps -ef|grep nginx|grep -v grep
netstat -anp|grep nginx

http://192.168.244.100:80
访问成功

配置域名 www.aaa.com
使用switchhosts
访问Nginx服务器成功

配置轮询,给客户端做代理就是正向代理,给服务器做代理就是反向代理
upstream aaa{
server 192.168.244.100:8180;
server 192.168.244.100:8280;
server 192.168.244.100:8380;
}

    server{
    listen 80;
    server_name www.aaa.com;

    location /{
    proxy_pass http://aaa;
    index index.jsp;

    }
    }

加载修改后的配置文件
[root@a conf]# …/sbin/nginx -s reload
浏览器运行负载均衡成功

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值