系统:Centos6.6 64位linux
Nginx: 目前最新版本1.9.4 我下载1.8.0nginx
下载模块依赖性Nginx须要依赖下面3个包
1.gzip 模块须要 zlib 库 ( 下载: http://www.zlib.NET/ )
2.rewrite 模块须要 pcre 库 ( 下载: http://www.pcre.org/ )
3.ssl 功能须要 openssl 库 ( 下载: http://www.openssl.org/ )
依赖包安装顺序依次为:openssl、zlib、pcre, 而后安装Nginx包c++
若是没有安装c++编译环境,还得安装,经过yum install gcc-c++完成安装
下载完成后:浏览器
下一步,编译安装tcp
openssl :spa
[root@localhost] tar zxvf openssl-fips-2.0.9.tar.gz.net
[root@localhost] cd openssl-fips-2.0.9ip
[root@localhost] ./config && make && make installssl
pcre:get
[root@localhost] tar zxvf pcre-8.36.tar.gz
[root@localhost] 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
经网上查询,这是Linux的通病
[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