系統: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