工具及软件
1. centos 7.x (安装在 vm 中)
2. nginx -1.6.2
3. 本机IP :192.168.1.220
4. 工作目录 /mytest
介绍 :
Nginx("engine x")是一款是由俄罗斯的程序设计师Igor Sysoev所开发高性能的 Web和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。
在高连接并发的情况下,Nginx是Apache服务器不错的替代品。
Nginx 安装
一、安装编译工具及库文件
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
二、安装 PCRE
PCRE 作用是让 Nginx 支持 Rewrite 功能。
1、下载 PCRE 安装包,
# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
# tar zxvf pcre-8.35.tar.gz
# cd pcre-8.35
# ./configure
# make && make install
# pcre-config --version
[root@finder220 keepalived]# pcre-config --version
8.35
安装 Nginx
# wget http://nginx.org/download/nginx-1.6.2.tar.gz
# tar zxvf nginx-1.6.2.tar.gz
# cd nginx-1.6.2
# ./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/mytest/pcre-8.35
# make && make install
# /usr/local/webserver/nginx/sbin/nginx -v
[root@finder220 mytest]# /usr/local/webserver/nginx/sbin/nginx -v
nginx version: nginx/1.6.2
至此,nginx安装完成
启动 Nginx
Nginx 启动命令如下:
# /usr/local/webserver/nginx/sbin/nginx
默认nginx监听80端口提供服务器
可以使用 命令查看
[root@finder220 ~]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 50136/nginx: master
访问站点
从浏览器访问我们配置的站点ip:
如果不是本机访问此服务器,外部电脑访问,可能访问不到,有可能是防火墙限制80端口对外访问
所以需要开发80端口
firewall-cmd --zone>public --add-port=80/tcp
firewall-cmd --reload 增加--permanent可以永久保留端口开放状态 必须直接 reload
监控 nginx状态
[root@finder220 ~]# vi /usr/local/webserver/nginx/conf/nginx.conf
添加 如下location
注意: s和{之间一定要有空格哦
重启 nginx
nginx -s stop
nginx 启动
注意: nginx -s reopen 重启命令好像无效 ,搞不明白 还是先停止 ,再使用启动命令
我们可以用 curl或者 WEB网页查看状态
[root@finder220 ~]# curl http://192.168.1.220/nginx_status
Active connections: 1
server accepts handled requests
4 4 2
Reading: 0 Writing: 1 Waiting: 0
状态参数说明
active connections – 活跃的连接数量
server accepts handled requests — 总共处理了7个连接 , 成功创建7次握手, 总共处理了3个请求
reading — 读取客户端的连接数.
writing — 响应数据到客户端的数量
waiting — 开启 keep-alive 的情况下,这个值等于 active – (reading+writing), 意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接.
server accepts handled requests — 总共处理了7个连接 , 成功创建7次握手, 总共处理了3个请求
reading — 读取客户端的连接数.
writing — 响应数据到客户端的数量
waiting — 开启 keep-alive 的情况下,这个值等于 active – (reading+writing), 意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接.
还可以使用 zabbix来监控nginx