Nginx访问状态统计虚拟主机设置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nginx访问状态统计虚拟主机设置相关的知识,希望对你有一定的参考价值。

Nginix内置了 HTTP_STUB_STATUS状态统计模块,用来反馈当前web的服务情况,那么,具体安装和使用原理是怎样的呢?可通过以下实验进行分析!

实验环境:一台Redhat6.5的虚拟机作为服务端:192.168.10.10
宿主机作为客户端:192.168.10.5
两台机子互联互通,共享文件、yum仓库等基本条件均已设置好
nginx包下载地址:http://nginx.org/en/download.html

实验过程:

一、nginx安装

1、安装编译环境、创建专门用户账号,更为安全

[[email protected] ~]# yum install pcre-devel zlib-devel gcc gcc-c++ make -y
[[email protected] ~]# useradd -M -s /sbin/nologin nginx       

2、安装nginx配置

解压安装包---执行配置--开启服务
技术分享图片

[[email protected] ~ ]# tar xzvf /opt/abc/nginx-1.6.0.tar.gz -C /opt/

技术分享图片

[[email protected] nginx-1.6.0]# make && make install
[[email protected] nginx-1.6.0]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/         #建立软连接
[[email protected] ~]# vim /etc/init.d/nginx

技术分享图片

[[email protected] ~]# chmod +x /etc/init.d/nginx
[[email protected] ~]# chkconfig --add nginx                     #添加为系统服务
[[email protected] ~]# nginx -t
[[email protected] ~]# nginx 

技术分享图片

二、配置统计页面

[[email protected] ~]# vim /usr/local/nginx/conf/nginx.conf
[[email protected] ~]# service nginx restart
[[email protected] ~]# service iptables stop
[[email protected] ~]# setenforce 0

技术分享图片

技术分享图片

用宿主机验证:

技术分享图片

三、基于域名的虚拟主机配置

配置文件末尾进行server配置

[[email protected] ~]# vim /usr/local/nginx/conf/nginx.conf
[[email protected] ~]# nginx -t
[[email protected] ~]# service nginx restart

技术分享图片

[[email protected] www]# mkdir /var/www/benet accp
[[email protected] www]# echo "this is benet" > benet/index.html
[[email protected] www]# echo "this is accp" > accp/index.html

技术分享图片
技术分享图片

DNS域名解析(此处如有疑问,请参考之前DNS正向解析)

[[email protected] ~]# rpm -ivh /mnt/Packages/bind-9.8.2-0.17.rc1.el6_4.6.x86_64.rpm 
[[email protected] ~]# vim /etc/named.conf 
         listen-on port 53 { any; };
         allow-query     { any; };
[[email protected] ~]# vim /etc/named.rfc1912.zones

技术分享图片

[[email protected] ~]# cd /var/named
[[email protected] named]# cp -p named.localhost benet.com.zone
[[email protected] named]# vim benet.com.zone

技术分享图片

[[email protected] named]# cp -p benet.com.zone accp.com.zone         #解析的IP地址与benet一样,因此不需要修改
[[email protected] ~]# service named start

技术分享图片

检测域名访问

技术分享图片

技术分享图片

以上是关于Nginx访问状态统计虚拟主机设置的主要内容,如果未能解决你的问题,请参考以下文章

Nginx服务构建及访问状态统计

python 来自nginx访问日志的HTTP状态代码统计信息

Nginx网络服务

Nginx虚拟主机及访问控制

Nginx网站服务

Nginx服务基本配置!