1、需要安装gcc的环境 yum install gcc-c++
2、第三方的开发包。
- PCRE
PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。
yum install -y pcre pcre-devel
注:pcre-devel是使用pcre开发的一个二次开发库。nginx也需要此库。
- zlib
zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。
yum install -y zlib zlib-devel
- openssl
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。
nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库。
yum install -y openssl openssl-devel
3、安装步骤
第一步:把nginx的源码包上传到linux系统(http://nginx.org 官网下载自己的版本)
第二步:tar -zxvf nginx-1.8.0.tar.gz
第三步:进入解压后目录,使用configure命令创建一makeFile文件
./configure \
--prefix=/usr/sunft/nginx \
--pid-path=/usr/sunft/nginx/log/nginx.pid \
--lock-path=/usr/sunft/log/nginx.lock \
--error-log-path=/usr/sunft/nginx/log/error.log \
--http-log-path=/usr/sunft/nginx/log/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/usr/sunft/nginx/temp/client \
--http-proxy-temp-path=/usr/sunft/nginx/temp/proxy \
--http-fastcgi-temp-path=/usr/sunft/nginx/temp/fastcgi \
--http-uwsgi-temp-path=/usr/sunft/nginx/temp/uwsgi \
--http-scgi-temp-path=/usr/sunft/nginx/temp/scgi
注意:启动nginx之前,上边将临时文件目录指定为/usr/sunft/nginx/temp/,需要在/usr下创建
第四步:在当前目录下 make && make install
第五步:进如/usr/sunft/nginx(编译后存放的目录)
第六步:进入sbin目录 ,执行./nginx
cd /usr/sunft/nginx 目录下:有如下4个目录
conf配置文件、HTML网页文件、log日志 文件、sbin启动文件 tmp临时文件
启动命令 : ./nginx
关闭命令: ./nginx -s stop or ./nginx -s quit
重启: ./nginx -s reload
(备注:由于nginx默认端口是80,我是用普通用户安装和启动的,启动会报错nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied),这是由于 1024以下端口启动时需要root权限,所以sudo nginx即可或修改conf/nginx.conf里面的80端口为其他)
第七步:查看nginx进程
第八步:访问http://ip:port