CentOS安裝nginx

1、下載安裝包

下載地址:http://nginx.org/en/download.html

2、安裝依賴

[root@140106 soft]# yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

3、解壓安裝包

[root@140106 soft]# tar -zxvf nginx-1.15.10.tar.gz
[root@140106 soft]# cd nginx-1.15.10

4、配置編譯安裝

[root@140106 nginx-1.15.10]# ./configure  --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module


[root@140106 nginx-1.15.10]# ./make
[root@140106 nginx-1.15.10]# make install
nginx大部分常用模塊,編譯時./configure --help以--without開頭的都默認安裝。

--prefix=PATH : 指定nginx的安裝目錄。默認 /usr/local/nginx
--conf-path=PATH : 設置nginx.conf配置文件的路徑。nginx允許使用不同的配置文件啓動,通過命令行中的-c選項。默認爲prefix/conf/nginx.conf
--user=name: 設置nginx工作進程的用戶。安裝完成後,可以隨時在nginx.conf配置文件更改user指令。默認的用戶名是nobody。--group=name類似
--with-pcre : 設置PCRE庫的源碼路徑,如果已通過yum方式安裝,使用--with-pcre自動找到庫文件。使用--with-pcre=PATH時,需要從PCRE網站下載pcre庫的源碼(版本4.4 – 8.30)並解壓,剩下的就交給Nginx的./configure和make來完成。perl正則表達式使用在location指令和 ngx_http_rewrite_module模塊中。
--with-zlib=PATH : 指定 zlib(版本1.1.3 – 1.2.5)的源碼解壓目錄。在默認就啓用的網絡傳輸壓縮模塊ngx_http_gzip_module時需要使用zlib 。
--with-http_ssl_module : 使用https協議模塊。默認情況下,該模塊沒有被構建。前提是openssl與openssl-devel已安裝
--with-http_stub_status_module : 用來監控 Nginx 的當前狀態
--with-http_realip_module : 通過這個模塊允許我們改變客戶端請求頭中客戶端IP地址值(例如X-Real-IP 或 X-Forwarded-For),意義在於能夠使得後臺服務器記錄原始客戶端的IP地址
--add-module=PATH : 添加第三方外部模塊,如nginx-sticky-module-ng或緩存模塊。每次添加新的模塊都要重新編譯(Tengine可以在新加入module時無需重新編譯)

5、編輯配置文件

[root@140106 nginx-1.15.10]# cd /usr/local/nginx/
[root@140106 nginx]# vim conf/nginx.conf

6、啓動停止和重啓

// 指定配置文件啓動
[root@140106 nginx]# ./sbin/nginx -c conf/nginx.conf

// 啓動後查看進程
[root@140106 nginx]# ps -ef|grep nginx
root     30533     1  0 16:11 ?        00:00:00 nginx: master process ./sbin/nginx -c conf/nginx.conf
nobody   30534 30533  0 16:11 ?        00:00:00 nginx: worker process
root     30542 27715  0 16:32 pts/0    00:00:00 grep --color=auto nginx

// 修改配置文件後重啓
[root@140106 nginx]# ./sbin/nginx -s reload

// 停止服務
[root@140106 nginx]# ./sbin/nginx -s stop

7、結束

愉快的玩耍去吧

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