系统:Centos6.6 64位
Nginx: 目前最新版本1.9.4 我下载1.8.0
下载模块依赖性Nginx需要依赖下面3个包
1.gzip 模块需要 zlib 库 ( 下载: http://www.zlib/ ) 2.rewrite 模块需要 pcre 库 ( 下载: http://www.pcre.org/ ) 3.ssl 功能需要 openssl 库 ( 下载: http://www.openssl.org/ ) 依赖包安装顺序依次为:openssl、zlib、pcre, 然后安装Nginx包
如果没有安装c++编译环境,还得安装,通过yum install gcc-c++完成安装
下载完成后:
下一步,编译安装
openssl :
[root] tar zxvf openssl-fips-2.0.9.tar.gz
[root] cd openssl-fips-2.0.9
[root] ./config && make && make install
pcre:
[root] tar zxvf pcre-8.36.tar.gz
[root] cd pcre-8.36
[root@localhost] ./configure && make && make install
zlib:
[root@localhost]tar zxvf zlib-1.2.8.tar.gz
[root@localhost] cd zlib-1.2.8
[root@localhost] ./configure && make && make install
最后安装nginx
[root@localhost]tar zxvf nginx-1.8.0.tar.gz
[root@localhost] cd nginx-1.8.0
[root@localhost] ./configure && make && make install
安装完成后,可启动nginx:
启动命令:/usr/local/nginx/sbin/nginx
发现报错了: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory 经网上查询,这是的通病 [root@localhost nginx]# sbin/nginx sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory [root@localhost nginx]# error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory [root@localhost nginx]# whereis libpcre.so.1 libpcre.so: /lib64/libpcre.so.0 /usr/local/lib/libpcre.so /usr/local/lib/libpcre.so.1 [root@localhost nginx]# ln -s /usr/local/lib/libpcre.so.1 /lib64 [root@localhost nginx]# sbin/nginx 先找到libpcre.so.1所在位置,然后做个软链接就可以了。 查看是否已启动:最后在浏览器输入ip:80即可 访问,正常如下:
注意:
1.启动Ngnix的时候提示错误,异常信息如下。
* Starting nginx nginx nginx: [emerg] bind() to [::]:80 failed (98: Address already in use) nginx: [emerg] bind() to [::]:80 failed (98: Address already in use) nginx: [emerg] bind() to [::]:80 failed (98: Address already in use) nginx: [emerg] bind() to [::]:80 failed (98: Address already in use) nginx: [emerg] bind() to [::]:80 failed (98: Address already in use) nginx: [emerg] still could not bind()
问题描述:端口已被使用。可能nginx服务卡死了,导致端口占用,出现此错误。
解决方案:
原因: 端口 80 端口被占用,用 “lsof -i:80" 命令查看一下是什么程序占用了80端口,然后kill之后再启动即可。
2.在虚拟机上安装的nginx由于防火墙原因有可能在本机上访问不了,所以可以关闭防火墙或者在配置 /etc/sysconfig/iptables 中添加 -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT