CentOS6.5下Nginx1.7.4安裝記錄

1.環境準備

yum -y install gcc gcc-c++ autoconf automake make


yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel 


不執行以上兩項安裝的話,就可能會遇到下面我的安裝過程中遇到的情況:


到此頁面下載自己想要的版本:

http://nginx.org/en/download.html

左側爲Linux版本,右側爲Windows版本


使用以下命令下載文件:wget http://nginx.org/download/nginx-1.7.4.tar.gz


解壓文件:tar -zxvf nginx-1.7.4.tar.gz 


切換目錄:cd nginx-1.7.4

配置:./configure


提示以下信息:./configure: error: the HTTP rewrite module requires the PCRE library.

You can either disable the module by using --without-http_rewrite_module

option, or install the PCRE library into the system, or build the PCRE library

statically from the source with nginx by using --with-pcre=<path> option.


要安裝pcre ,他作用是讓ngnix支持rewrite功能

使用命令安裝:yum install pcre-devel.i686


輸入y,回車


最後提示Complete,說明安裝成功:


再執行./configure

還是提示同樣的錯誤;

執行命令查找PCRE的安裝位置:file -name pcre

得到的是:./auto/lib/pcre


根據提示在後面添加參數指定Path

執行命令:./configure --with-pcre=./auto/lib/pcre

提示如下信息:

./configure: error: the HTTP gzip module requires the zlib library.

You can either disable the module by using --without-http_gzip_module

option, or install the zlib library into the system, or build the zlib library

statically from the source with nginx by using --with-zlib=<path> option.

 

還缺少zlib library信息!

執行以下命令安裝:yum -y install make zlib zlib-devel gcc-c++ libtool

安裝成功之後,再執行命令:./configure --with-pcre=./auto/lib/pcre

最後的提示信息如下:


應該是配置成功了,執行以下命令安裝:

make && make install

提示以下錯誤:


該裝的都裝了,還是無法安裝,最後執行以下命令解決問題:

yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel

執行之後再執行:./configure

再執行:make && make install

安裝完成!


記住上圖中的一些目錄位置!

修改配置文件:

切換目錄:cd /usr/local/nginx/conf

修改文件:vi nginx.conf

主要是修改server配置節的內容,按字母i進入編輯模式


ESC鍵,退出編輯模式,按冒號鍵“:”進入命令模式,輸入“wq”然後回車,保存並退出;

 

切換到sbin目錄:cd /usr/local/nginx/sbin

啓動Nginx:./nginx

開放防火牆端口:

/sbin/iptables -I INPUT -p tcp --dport 88 -j ACCEPT

/etc/init.d/iptables save

 

打開瀏覽器,輸入以下地址訪問吧:

http://你的服務器IP:88/

看到以下信息了嗎?


我是看到了,看不到的朋友繼續努力吧!


注意:我在虛擬機中安裝的時候遇到了類似以下錯誤:

./configure auto/unix: No such file or directory

當我使用“mkdir auto/unix”之後,還是提示類似的錯誤,但目錄名又變了。

糾結了好久,後來發現是解壓的時候就有好多文件沒有解壓出來,判斷應該是安裝包壓縮文件壞了,

所以解壓的時候就少了好多的文件或目錄,重新下載一個解壓安裝問題就解決了。


配置Nginx開機啓動vi /etc/rc.d/rc.local

在文件末尾添加“/usr/local/nginx/sbin/nginx


Nginx常用命令:

重新加載配置文件:/usr/local/nginx/sbin/nginx -s reload

停止Nginx服務:/usr/local/nginx/sbin/nginx -s stop

其它Nginx命令:


[plain] view plaincopy在CODE上查看代碼片派生到我的代碼片

  1. /usr/local/nginx/sbin/nginx -h  

  2. nginx version: nginx/1.7.5  

  3. Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]  

  4.   

  5. Options:  

  6.   -?,-h         : this help  

  7.   -v            : show version and exit  

  8.   -V            : show version and configure options then exit  

  9.   -t            : test configuration and exit  

  10.   -q            : suppress non-error messages during configuration testing  

  11.   -s signal     : send signal to a master process: stop, quit, reopen, reload  

  12.   -p prefix     : set prefix path (default: /usr/local/nginx/)  

  13.   -c filename   : set configuration file (default: conf/nginx.conf)  

  14.   -g directives : set global directives out of configuration file  


文件權限問題:

有可能因爲目錄、文件權限過高,導致Nginx無權訪問文件,可以通過以下命令修改權限:

chmod -R 777 ./uploadfile


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章