Nginx高性能web服務器之安裝(二)

天天堅持寫一篇博文j_0003.gif今天開始寫Nginx的簡單安裝方式,明天繼續詳解下Nginx的配置文件和一些參數,僅供參考!linux


1、準備一臺虛擬機:nginx

       ip:192.168.1.214瀏覽器

      關閉防火牆和設置selinux爲disabledbash

[root@localhost ~]service iptables stop
[root@localhost ~]chkconfig iptables off
[root@localhost ~]sed -i's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config


2、在安裝Nginx以前,首先要確保安裝了gcc,openssl-devel,pcre-devel,zilb-devel軟件庫。app

       安裝pcre是使nginx支持http rewrite模塊,安裝也很簡單,過程以下:tcp

下載官網: 
[root@localhost ~]#yum install -y pcre-devel
[root@localhost ~]#tar zxvf nginx-1.2.9.tar.gz 
[root@localhost ~]#cd nginx-1.2.9
[root@localhost ~]#./configure \
--with-http_stub_status_module \ #啓用nginx的nginxstauts功能,以監控nginx當前狀態
--prefix=/application/nginx \    #Nginx的安裝路徑
--with-http_gzip_static_module   #啓用HttpGzip模塊
make && make install
#如此,pcre就安裝好了!

  

提示:其實Nginx的安裝也很簡單,默認下,通過編譯安裝的Nginx已經有了不少能夠用的模塊了。ide

  咱們能夠用"./configure --help"查看每一個模塊的使用狀況。spa

  例如:不安裝http_ssi模塊rest

  執行:--without-http_ssi_module blog

 3、Nginx的安裝過程以下:

 [root@localhost ~]# tar zxvf nginx-1.6.0.tar.gz 
 [root@localhost ~]# cd nginx-1.6.0
 
 [root@localhost ~]# ./configure   
--prefix=/usr/local \
--sbin-path=/usr/sbin/nginx \  
--conf-path=/etc/nginx/nginx.conf \ 
--error-log-path=/var/log/nginx/error.log \  
--http-log-path=/var/log/nginx/access.log \ 
--pid-path=/var/run/nginx/nginx.pid \ 
--lock-path=/var/lock/nginx.lock \
--user=nginx \   
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \  
--with-http_gzip_static_module \ 
--http-client-body-temp-path=/var/tmp/nginx/client/ \  
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \  
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \  
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \  
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--with-pcre
[root@localhost ~]# make && make install

#啓動Nginx
[root@localhost ~]#/usr/sbin/nginx

#查看端口是否啓動
[root@localhost ~]# netstat -lntup|grep nginx
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      1072/nginx

   Nginx安裝完成以後,在瀏覽器中輸入IP:192.168.1.214

 如圖出現Nginx的歡迎界面,表示已經成功了!j_0003.gif

wKioL1UpP7rDwhfcAAHASuksSEc848.jpg

   其中Nginx還有一些經常使用命令:

#檢查語法
/usr/sbin/nginx –t

#平滑重啓
/usr/sbin/nginx –sreload

#不間斷服務重啓,將 pid 行程重跑 (restart)
Kill –HUP  `cat /opt/nginx/logs/nginx.pid`

#關閉
Kill 進程號

    

4、添加編譯模塊 

 安裝好nginx以後,若是如今須要添加一個未被編譯安裝的模塊,咱們該如何作呢?

nginx -V ==>能夠查看原來編譯時都帶了哪些參數

添加的參數:
--with-http_stub_status_module  
--with-http_ssl_module 
--with-http_realip_module

步驟以下:
1. 使用參數從新配置: ./configure 
--user=nginx \
--group=nginx \
--prefix=/application/nginx1.6.2 \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-http_ssl_module--add-module=../nginx_upstream_hash-0.3.1/\
--add-module=../gnosek-nginx-upstream-fair-2131c73/

2. 編譯:
make

注意:不要make install,不然就是覆蓋安裝

還有能夠經過官方查看模塊安裝例子http://nginx.org/en/docs/

相關文章
相關標籤/搜索