Linux 安裝nginx伺服器詳細介紹_nginx

來源:互聯網
上載者:User

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

感謝閱讀,希望能協助到大家,謝謝大家對本站的支援!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.