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"′25′status
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
浏览器运行负载均衡成功