nginx依賴一些軟件庫,在安裝之前請確保系統安裝了gcc、ssl、pcre和gzip等軟件,可以用rpm -q 命令查看軟件是否安裝。
[root@RedHat1 ~]# rpm -q gcc
gcc-4.1.2-44.el5
依賴庫信息如下:
(1). gzip 模塊需要 zlib 庫 ( 下載: http://www.zlib.net/ )
(2). rewrite 模塊需要 pcre 庫 ( 下載: http://www.pcre.org/)
(3). ssl 功能需要 openssl 庫 ( 下載: http://www.openssl.org/)
如安裝pcre,下載pcre至目的目錄下,這里選擇的版本是pcre-8.38,下載完后執行以下操作
tar -zxvf pcre-8.38.tar.gzcd pcre-8.38./configuremakemake install
安裝nginx,執行如下命令
在默認情況下,經過編譯安裝的Nginx已經包含了大部分可用模塊,可以通過“./configure --help”選項設置各個模塊的使用情況,例如對不需要的http_ssi模塊,可通過“--without-http_ssi_module”參數關閉此模塊;如果需要“http_perl”模塊,則可以通過“--with-http_perl_module”參數安裝此模塊。執行以下操作進行安裝。
tar -zxvf nginx-1.11.1.tar.gzcd nginx-1.11.1./configure --with-pcre=../pcre-8.38 --prefix=/usr/local/nginxmakemake install
檢測是否安裝成功,執行命令如下
[root@RedHat1 sbin]# cd /usr/local/nginx/sbin
[root@RedHat1 sbin]# ./nginx -t
出現如下信息證明安裝成功
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
啟動nginx
[root@RedHat1 sbin]# ./nginx
查看端口
[root@RedHat1 sbin]# netstat -ntlp
結果如下:
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN 2993/hpiod
tcp 0 0 0.0.0.0:834 0.0.0.0:* LISTEN 2772/rpc.statd
tcp 0 0 0.0.0.0:11111 0.0.0.0:* LISTEN 3391/ricci
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 2733/portmap
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3852/nginx
tcp 0 0 0.0.0.0:16851 0.0.0.0:* LISTEN 3290/modclusterd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 3024/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 3057/sendmail: acce
tcp 0 0 127.0.0.1:2207 0.0.0.0:* LISTEN 2998/python
tcp 0 0 :::22 :::* LISTEN 3013/sshd
也可以在瀏覽器中輸入:http://localhost來驗證是否啟動成功。
停止nginx
停止操作是通過向nginx進程發送信號來進行的
步驟1:查詢nginx主進程號:
ps -ef | grep nginx
在進程列表里 面找master進程,它的編號就是主進程號了。
步驟2:發送信號
從容停止Nginx:kill -QUIT 主進程號
快速停止Nginx:kill -TERM 主進程號
強制停止Nginx:pkill -9 nginx
重啟nginx:平滑重啟
如果更改了配置就要重啟Nginx,要先關閉Nginx再打開?不是的,可以向Nginx 發送信號,平滑重啟。
平滑重啟命令:
kill -HUP 住進稱號或進程號文件路徑 或者 /usr/local/nginx/sbin/nginx -s reload
注意,修改了配置文件后最好先檢查一下修改過的配置文件是否正 確,以免重啟后Nginx出現錯誤影響服務器穩定運行。判
斷Nginx配置是否正確命令如下:
nginx -t -c /usr/local/nginx/conf/nginx.conf 或者 /usr/local/nginx/sbin/nginx -t
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
新聞熱點
疑難解答