linux下安裝nginx

來源:互聯網
上載者:User
linux系統為Centos 64位

第一步:從http://nginx.org/download/上下載相應的版本(或者wget http://nginx.org/download/nginx-1.5.9.tar.gz直接在Linux上用命令下載)

第二步:解壓 tar -zxvf nginx-1.5.9.tar.gz

第三步:設定一下配置資訊 ./configure --prefix=/usr/local/nginx ,或者不執行此步,直接預設配置

第四步:

make 編譯 (make的過程是把各種語言寫的源碼檔案,變成可執行檔和各種庫檔案)

make install 安裝 (make install是把這些編譯出來的可執行檔和庫檔案複製到合適的地方)

在配置資訊的時候,也就是在第三步,出現了一下錯誤:

錯誤為:./configure: error: the HTTP rewrite module requires the PCRE library.

安裝pcre-devel解決問題
yum -y install pcre-devel

還有可能出現:

錯誤提示:./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library. You can either disable the module by using
--without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
--with-http_ssl_module --with-openssl= options.

解決辦法:

yum -y install openssl openssl-devel

安裝後在linux下啟動和關閉nginx:

啟動操作

/usr/nginx/sbin/nginx (/usr/nginx/sbin/nginx -t 查看配置資訊是否正確)

停止操作
停止操作是通過向nginx進程發送訊號(什麼是訊號請參閱linux文 章)來進行的
步驟1:查詢nginx主進程號
ps -ef | grep nginx
在進程列表裡 面找master進程,它的編號就是主進程號了。
步驟2:發送訊號
從容停止Nginx:
kill -QUIT 主進程號
快速停止Nginx:
kill -TERM 主進程號
強制停止Nginx:
pkill -9 nginx
另外, 若在nginx.conf配置了pid檔案存放路徑則該檔案存放的就是Nginx主進程號,如果沒指定則放在nginx的logs目錄下。有了pid文 件,我們就不用先查詢Nginx的主進程號,而直接向Nginx發送訊號了,命令如下:
kill -訊號類型 '/usr/nginx/logs/nginx.pid'
平滑重啟
如果更改了配置就要重啟Nginx,要先關閉Nginx再開啟?不是的,可以向Nginx 發送訊號,平滑重啟。
平滑重啟命令:
kill -HUP 住進稱號或進程號檔案路徑

或者使用

/usr/nginx/sbin/nginx -s reload

注意,修改了設定檔後最好先檢查一下修改過的設定檔是否正 確,以免重啟後Nginx出現錯誤影響伺服器穩定運行。判斷Nginx配置是否正確命令如下:
nginx -t -c /usr/nginx/conf/nginx.conf

或者

/usr/nginx/sbin/nginx -t

如:

以上就介紹了linux下安裝nginx,包括了方面的內容,希望對PHP教程有興趣的朋友有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.