1. 下载 nginx
从http://nginx.org/download/上下载相应的版本(或者http://nginx.org/download/nginx-1.10.2.tar.gz
直接在Linux上用命令下载)
[root@besttest tomcat6]# wget http://nginx.org/download/nginx-1.10.2.tar.gz
-bash: wget: command not found
安装wget:
yum -y install wget
在执行下载nginx
通过find / -name nginx-1.10.2.tar.gz 确认下载文件的路径
2. 解压
解压命令:
tar -zxvf nginx-1.10.2.tar.gz
mv nginx-1.10.2 nginx 重命名下
3.编译
cd nginx
执行 ./configure 生成Makefile时遇到的问题
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using –without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using –with-pcre= option.
没装伪静态模块需要pcre库
解决方法:
yum install -y pcre pcre-devel
还有可能出现:
错误提示:./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library. You can either disable the module by using
–without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
–with-http_ssl_module –with-openssl= options.
解决办法:
yum -y install openssl openssl-devel
执行make 编译
4. 安装
执行make install 命令进行编译时遇到的问题:
问题原因: 直接把安装包重命名成nginx了,安装文件没有路径了。
解决办法如下:
删除nginx 文件夹
rm -rf nginx
重新解决源码
tar -zxvf nginx-1.10.2.tar.gz
cd /usr/local/nginx-1.10.2
生成Makefile文件
./configure --prefix=/usr/local/nginx
编译源码
make
安装
make install
5. 启动nginx 服务
[root@besttest ~]# whereis nginx
nginx: /usr/local/nginx
启动命令./nginx , 遇到端口已绑定
netstat -ntpl 查看到80端口被占用了
解决方法:
kill 1226 进程
执行./nginx 启动服务
还可以通过ps -ef |grep nginx 查询nginx主进程号
6. 停止服务
./nginx -s stop
7. 补充说明
因安装nginx 时的系统环境不同 , 可能需要依赖的库有所不同,先归纳下nginx安装需要依赖的库:
选首先安装这几个软件:GCC,PCRE(Perl Compatible Regular Expression),zlib,OpenSSL。
Nginx是C写的,需要用GCC编译;Nginx的Rewrite和HTTP模块会用到PCRE;Nginx中的Gzip用到zlib;
用命令“ gcc”,查看gcc是否安装;如果出现“gcc: no input files”信息,说明已经安装好了。
否则,就需要用命令“ yum -y install gcc”,进行安装了!一路可能需要多次输入y,进行确认。
安装好后,可以再用命令“gcc”测试,或者用命令“ gcc -v”查看其版本号。
同样方法,用如下命令安装PCRE,zlib,OpenSSL(其中devel,是develop开发包的意思):
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel