如何快速安裝Nginx?
下面介紹一下Centos下安裝Nginx的方法
Nginx的官網(wǎng):http://nginx.org/ ,Nginx有三個版本:穩(wěn)定版、開發(fā)版和歷史穩(wěn)定版。開發(fā)版更新快,包含最新的功能和bug修復(fù),但同時也可能會出現(xiàn)新的bug。開發(fā)版一旦更新穩(wěn)定下來,就會被加入穩(wěn)定版分支,穩(wěn)定版更新較慢,但bug較少,所以生產(chǎn)環(huán)境優(yōu)先選擇穩(wěn)定版。
一、下載Nginx安裝文件目前最新穩(wěn)定版:
http://nginx.org/download/nginx-1.16.0.tar.gz
,可以先下載好安裝文件再通過ftp上傳的CentOS上,也可以在CentOS上直接通過wget命令下載,這里我將文件下載到了/home/software文件夾下,如下:[root@localhost software]# pwd/home/software[root@localhost software]# wget http://nginx.org/download/nginx-1.10.1.tar.gz二、解壓安裝文件[root@songguoliang software]# tar -xzvf nginx-1.10.1.tar.gz 三、執(zhí)行configure命令通過cd命令進入Nginx解壓文件目錄,執(zhí)行該目錄下的configure命令,--prefix是打算將Nginx安裝在哪個目錄。在執(zhí)行configure命令之前,確保安裝了gcc、openssl-devel、pcre-devel和zlib-devel軟件庫(gzip模塊需要 zlib 庫,rewrite模塊需要 pcre 庫,ssl 功能需要openssl庫),也可以直接執(zhí)行configure命令,根據(jù)提示缺少的軟件庫安裝,下面有缺少相應(yīng)庫報的錯誤信息和安裝依賴庫的方法。
為了方便,我們可以先安裝一下必須的軟件庫。
[root@localhost software]# yum -y install gcc pcre-devel zlib-devel openssl-devel出現(xiàn)類似下圖信息或提示之前已經(jīng)安裝過等信息,說明已經(jīng)安裝好依賴庫。如下:
這樣事先安裝好依賴庫后,就不必看下面幾個處理錯誤的步驟了,直接進行configure,如下:
[root@localhost software]# cd nginx-1.10.1[root@localhost nginx-1.10.1]# pwd/home/software/nginx-1.10.1[root@localhost nginx-1.10.1]# ./configure --prefix=/usr/local/nginx1、如果報下面錯誤,說明還沒有安裝gcc編譯環(huán)境,可以通過yum在線安裝功能安裝gcc,重新執(zhí)行configure命令。
[root@localhost nginx-1.10.1]# ./configure --prefix=/usr/local/nginxchecking for OS + Linux 2.6.32-431.el6.x86_64 x86_64checking for C compiler ... not found ./configure: error: C compiler cc is not found在線安裝gcc:
[root@localhost nginx-1.10.1]# yum install gcc2、如果報下面的錯誤,說明沒有安裝pcre-devel庫,通過yum在線安裝pcre后,重新執(zhí)行configure命令。
./configure: error: the HTTP rewrite module requires the PCRE library.You can either disable the module by using --without-http_rewrite_moduleoption, or install the PCRE library into the system, or build the PCRE librarystatically from the source with nginx by using --with-pcre=<path> option.在線安裝pcre-devel庫:
[root@localhost nginx-1.10.1]# yum -y install pcre-devel-y參數(shù)表示使用yum在線安裝時,如果需要用戶輸入Y/N時自動輸入Y。
3、如果報下面的錯誤,說明沒有安裝zlib庫,安裝zlib庫后重新執(zhí)行configure命令。
./configure: error: the HTTP gzip module requires the zlib library.You can either disable the module by using --without-http_gzip_moduleoption, or install the zlib library into the system, or build the zlib librarystatically from the source with nginx by using --with-zlib=<path> option.在線安裝zlib庫:
[root@localhost nginx-1.10.1]# yum -y install zlib-devel4、如果報以下錯誤,說明沒有安裝OpenSSL庫,安裝OpenSSL庫后重新執(zhí)行configure命令。
./configure: error: SSL modules require the OpenSSL library.You can either do not enable the modules, or install the OpenSSL libraryinto the system, or build the OpenSSL library statically from the sourcewith nginx by using --with-openssl=<path> option.在線安裝openssl庫:
[root@localhost nginx-1.10.1]# yum install openssl-devel執(zhí)行configure命令成功后,顯示如下信息:
checking for zlib library ... foundcreating objs/Makefile Configuration summary + using system PCRE library + OpenSSL library is not used + using builtin md5 code + sha1 library is not found + using system zlib library nginx path prefix: "/usr/local/nginx" nginx binary file: "/usr/local/nginx/sbin/nginx" nginx modules path: "/usr/local/nginx/modules" nginx configuration prefix: "/usr/local/nginx/conf" nginx configuration file: "/usr/local/nginx/conf/nginx.conf" nginx pid file: "/usr/local/nginx/logs/nginx.pid" nginx error log file: "/usr/local/nginx/logs/error.log" nginx http access log file: "/usr/local/nginx/logs/access.log" nginx http client request body temporary files: "client_body_temp" nginx http proxy temporary files: "proxy_temp" nginx http fastcgi temporary files: "fastcgi_temp" nginx http uwsgi temporary files: "uwsgi_temp" nginx http scgi temporary files: "scgi_temp"四、執(zhí)行make命令[root@localhost nginx-1.10.1]# make五、執(zhí)行make install命令[root@localhost nginx-1.10.1]# make install步驟四和步驟五可以合并執(zhí)行如下命令,連接符 && 代表前面一個命令如果執(zhí)行成功則繼續(xù)執(zhí)行后面的命令,如果前面命令執(zhí)行失敗則不再執(zhí)行后面的命令。而 || 表示如果前面的命令執(zhí)行成功則不執(zhí)行后面的命令,如果前面的命令執(zhí)行失敗則繼續(xù)執(zhí)行后面的命令
[root@localhost nginx-1.10.1]# make && make install六、啟動Nginx服務(wù)[root@localhost nginx-1.10.1]# cd /usr/local/nginx/[root@localhost nginx]# ll總用量 16drwxr-xr-x. 2 root root 4096 10月 1 23:35 confdrwxr-xr-x. 2 root root 4096 10月 1 23:35 htmldrwxr-xr-x. 2 root root 4096 10月 1 23:35 logsdrwxr-xr-x. 2 root root 4096 10月 1 23:35 sbin[root@songguoliang nginx]# ./sbin/nginx通過瀏覽器訪問Nginx,顯示如下welcome to nginx!頁面便表示安裝成功:
nginx啟動、重啟、重新加載配置文件和平滑升級nginx啟動、重啟、重新加載配置文件和平滑升級可以參考我博客
https://blog.csdn.net/gnail_oug/article/details/52754491
以上回答希望能對你有幫助