一.Nginx简介
Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好,中国大陆使用nginx网站用户有:百度、京东、新浪、网易、腾讯、淘宝等。
二.nginx的安装
- 准备工作
系统平台:RedHat6.5
配置安装环境:配置Reedaht6.5的yum源,并安装http服务
- 安装Nginx
第一步:安装编译工具以及库文件
yum install gcc openaal apenssl-devel make -y
第二步:安装PCRE
- PCRE的作用是让Nginx支持Rewrite功能
yum install pcre -y
- 查看PCRE的版本
[root@localhost ~]# pcre-config --version
7.8
第三步:安装Nginx
- 下载Nginx的安装包,并解压
tar zxf nginx-1.14.0.tar.gz
- 进入解压后的目录下,编辑src/core/nginx.h和auto/cc/gcc文件
cd nginx-1.14.0
编辑src/core/nginx.h文件
14 #define NGINX_VER "nginx/"
编辑auto/cc/gcc文件
171 # debug
172 #CFLAGS="$CFLAGS -g"
编辑src/core/nginx.h文件
编辑auto/cc/gcc文件
注意:这两个文件可编辑,也可以不编辑
第四步:编译安装
[root@localhost nginx-1.14.0]# ./configure --prefix=/usr/local/nginx --with-threads --with-file-aio --with-http_ssl_module --with-http_stub_status_module --user=nginx --group=nginx
[root@localhost nginx-1.14.0]# make && make install
第五步:为了方便管理,创建一个软链接
[root@localhost sbin]# ln -s /usr/local/nginx/sbin /usr/local/sbin/
[root@localhost sbin]# ll /usr/local/sbin/
total 0
lrwxrwxrwx. 1 root root 21 Jan 7 20:33 sbin -> /usr/local/nginx/sbin
第六步:创建Niginx运行使用的用户
第六步:启动nginx
- 首先查看nginx安装在什么位置
[root@localhost sbin]# whereis nginx
nginx: /usr/local/nginx
- 进入nginx目录并启动
[root@localhost sbin]# pwd
/usr/local/nginx/sbin
[root@localhost sbin]# ./nginx ##用绝对路径开启nginx
测试:
关闭火墙,在浏览器中输入172.25.254.127进行测试
/etc/init.d/iptables stop
三.nginx的基本操作
开启
/usr/local/nginx/sbin/nginx
停止
/usr/local/nginx/sbin/nginx -s stop(quit,reload)
文件配置检测
/usr/local/nginx/sbin/nginx -h
/usr/local/nginx/sbin/nginx -t
编辑配置文件
/usr/local/nginx/conf/nginx.conf
卸载
yum remove nginx
或者rm -fr /usr/local/nginx/ ##删除所有关于nginx的文件
which nginx ##查看nginx是否卸载干净
[root@localhost html]# which nginx
/usr/bin/which: no nginx in (/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)即为卸载干净