正式開始安裝前,編譯環境gcc g++ 開發庫之類的需要提前裝好,這裏默認你已經裝好。
shell># yum -y install gcc gcc-c++
- 創建www組與www用戶
shell># groupadd www shell># useradd -g www -s /usr/sbin/nologin www
- 安裝PCRE庫(重寫rewrite)
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ 下載最新的 PCRE 源碼包,使用下面命令下載編譯和安裝 PCRE 包: shell># wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz shell># tar -zxvf pcre-8.40.tar.gz shell># cd pcre-8.40 shell># ./configure && make && make install
- 安裝zlib庫(gzip壓縮)
ftp://ftp.simplesystems.org/pub/png/src/zlib 下載最新的 zlib 源碼包 shell>#wget ftp://ftp.simplesystems.org/pub/png/src/zlib/zlib-1.2.11.tar.gz shell>#tar -zxvf zlib-1.2.11.tar.gz shell>#cd zlib-1.2.11 shell>#./configure && make && make install
- 安裝ssl(某些vps默認沒裝ssl)
shell>#wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz shell>#tar -zxvf openssl-1.0.1c.tar.gz shell>#./config && make && make install
- 安裝nginx
shell>#wget http://nginx.org/download/nginx-1.6.0.tar.gz shell>#tar -zxvf nginx-1.6.0.tar.gz shell>#cd nginx-1.6.0 shell>#./configure --sbin-path=/usr/local/nginx \ --conf-path=/usr/local/nginx/nginx.conf \ --pid-path=/usr/local/nginx/nginx.pid \ --with-http_ssl_module \ --with-pcre=/home/software/pcre-8.40 \ --with-zlib=/home/software/zlib-1.2.11 \ --with-openssl=/home/software/openssl-1.0.1c shell>#make && make install
- Nginx基本操作
關閉Nginx shell>#ps -ef | grep nginx shell>#kill -quit 進程號 啓動Nginx shell>#./nginx -c /usr/local/web/nginx/conf/nginx.conf nginx重啓 shell>#./nginx -s reload
- 安裝過程報錯的解決方案
安裝如果報錯爲Nginx: error while loading shared libraries: libpcre.so.1 具體網站可參考http://www.2cto.com/os/201304/199770.html 找到libpcre.so.1文件路徑 shell>#ln -s /lib/libpcre.so.0.0.1 /lib/libpcre.so.1 shell>#ln -s /usr/local/lib/libpcre.so.1 /lib64/
- 開放iptables的80端口
在Linux中設置防火牆,以CentOS爲例,打開iptables的配置文件: shell>#vi /etc/sysconfig/iptables 如果沒有iptables文件,則將iptables.old複製一份iptables文件 shell>#cp /etc/sysconfig/iptables.old /etc/sysconfig/iptables 通過/etc/init.d/iptables status命令查詢是否有打開80端口,如果沒有可通過兩種方式處理: 方式一: 1.修改vi /etc/sysconfig/iptables命令添加使防火牆開放80端口 -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT 2.關閉/開啓/重啓防火牆 shell>#/etc/init.d/iptables stop #關閉 shell>#/etc/init.d/iptables start #開啓 shell>#/etc/init.d/iptables restart #重啓 方式二:永久性關閉防火牆 shell>#chkconfig --level 35 iptables off shell>#/etc/init.d/iptables stop shell>#iptables -P INPUT DROP
最後我在瀏覽器的地址欄中輸入:localhost 出現如下圖所示表示Nginx安裝成功
至此Nginx安裝完成。