Nginx
服务器ip地址为:192.168.1.30
使用yum安装Nginx源代码包,需要搭建一个yum仓库,这里简单的搭建一个域名仓库
/etc/yum.repos.d/rhel-source.repo 这是系统自带的,可以参考下。
[root@wan3 ~]# mount /dev/cdrom /mnt/ 将光盘挂在到/mnt目录
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@wan3 ~]# vi /etc/yum.repos.d/local.repo 这是简单搭建的yum仓库
[local]
name=user
baseurl=file:///mnt 这个路径一定不要写错
enabled=1
gpgcheck=0
可以使用yum list 查看是否搭建成功
[root@wan3 ~]# yum list
Loaded plugins: product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
local | 3.9 kB 00:00 ...
local/primary_db | 3.1 MB 00:00 ...
在安装nginx之前要安装以下插件 不安装的话在编译的时候会报错:
[root@wan3 ~]# yum install -y gcc gcc-c++ cmake
安装依赖包:yum -y install pcre-devel zlib-devel
[root@wan3 ~]# useradd -M -s /sbin/nologin nginx
[root@wan3 ~]# tar xzvf nginx-1.6.0.tar.gz -C /opt/ 解压缩包。将其放到/opt目录
[root@wan3 ~]# ls /opt/ 查看/opt是否有nginx
nginx-1.6.0
配置编译安装:
[root@wan3 ~]# cd /opt/nginx-1.6.0/ cd到源代码目录
root@wan3 ~]# ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module
[root@wan3 nginx-1.6.0]# make
[root@wan3 nginx-1.6.0]# make install
做个软连接让系统识别:
[root@wan3 nginx-1.6.0]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
-----检查、启动、重启、停止--------
nginx -t //检查
nginx //启动
killall -1 nginx //重启
killall -3 nginx //停止
制作管理角本:可以使用service 管理:
[root@wan3 nginx-1.6.0]# vi /etc/init.d/nginx
#!/bin/bash
# chkconfig: 35 99 20
# description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
$PROG
;;
stop)
kill -s QUIT $(cat $PIDF)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
esac
exit 0
[root@wan3 nginx-1.6.0]# chmod +x /etc/init.d/nginx 增加可执行权限
[root@wan3 nginx-1.6.0]# chkconfig --add nginx 增加一项新的服务,即nginx
[root@wan3 nginx-1.6.0]# service nginx start 开启nginx
[root@wan3 nginx-1.6.0]# netstat -anpt | grep 80 查看80端口
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3592/nginx
[root@wan3 nginx-1.6.0]# service iptables stop
iptables:将链设置为政策 ACCEPT:filter [确定]
iptables:清除防火墙规则: [确定]
iptables:正在卸载模块: [确定]
[root@wan3 nginx-1.6.0]# setenforce 0
访问:192.168.1.30 出来这样画面就说明安装成功了。
配置统计页面: 主配置问件是: nginx.conf
[root@wan3 nginx-1.6.0]# cd /usr/local/nginx/conf/
[root@wan3 conf]# mv nginx.conf nginx.conf.back 将主配置文件备份
[root@wan3 conf]# grep -v "#" nginx.conf.back > nginx.conf 将#部分过滤并追加到nginx.conf
[root@wan3 conf]# vi nginx.conf
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
只需要加红色部分的命令即可
location ~ /status { //访问位置为/status
stub_status on; //打开状态统计功能
access_log off; //关闭此位置的日志记录
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
[root@wan3 conf]# service nginx restart 重启服务器
访问地址:192.168.1.30/status 刷新数字随之改变