技術(shù)員聯(lián)盟提供win764位系統(tǒng)下載,win10,win7,xp,裝機純凈版,64位旗艦版,綠色軟件,免費軟件下載基地!

當(dāng)前位置:主頁 > 教程 > 服務(wù)器類 >

CentOS 7.2如何安裝Nginx 1.10.2

來源:技術(shù)員聯(lián)盟┆發(fā)布時間:2017-04-13 10:05┆點擊:

  一、使用Yum安裝(推薦)

  使用Yum安裝是推薦的方式,整體的流程非常的簡單,也不容易出錯,如果不需要什么特殊配置,建議使用Yum盡進行安裝。

  1、安裝epel-release源并進行安裝

  yum install epel-release

  yum update

  yum install nginx

  2、執(zhí)行相關(guān)的應(yīng)用操作

  systemctl start nginx #啟動

  systemctl stop nginx #停止

  systemctl restart nginx #重啟

  systemctl status nginx #查看運行狀態(tài)

  systemctl enable nginx #開機啟動

  3、設(shè)置防火墻

  在啟動完以后可能無法通過IP訪問,需要進一步設(shè)置防火墻

  firewall-cmd --permanent --zone=public --add-service=http

  firewall-cmd --permanent --zone=public --add-service=https

  firewall-cmd --reload

  至此,安裝完畢。

  參考文章:https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-centos-7

  二、通過源碼編譯安裝

  1、安裝編譯所需工具

  yum groupinstall "Development Tools"

  yum install wget

  2、到官網(wǎng)下載最新的源代碼(https://nginx.org/en/)

  cd /usr/local/src

  wget

  tar zxvf nginx-1.10.2.tar.gz

  3、安裝依賴包

  yum install zlib zlib-devel openssl openssl-devel pcre pcre-devel

  zlib: 為nginx提供gzip模塊,需要zlib庫支持,傳輸數(shù)據(jù)打包,省流量(但消耗資源)

  openssl: 為nginx提供ssl功能

  pcre: 為支持地址重寫rewrite功能

  4、創(chuàng)建用來運行nginx的用戶及組

  groupadd nginx

  useradd -g nginx -M nginx –s /sbin/nologin

  -g參數(shù)為nginx用戶指定了一個組。-M參數(shù)保證其不自動生成home目錄。

  5、編譯源代碼

  先使用./configure –help 查看編譯幫助:

  [root@localhost nginx-1.10.2]# ./configure --help

  --help print this message

  --prefix=PATH set installation prefix #Nginx安裝的根路徑,默認(rèn)為 /usr/local/nginx。

  --sbin-path=PATH set nginx binary pathname #指定nginx二進制文件的路徑,默認(rèn)為PATH/sbin/nginx。

  --modules-path=PATH set modules path #Perl模塊位置

  --conf-path=PATH set nginx.conf pathname #設(shè)定nginx配置文件地址,默認(rèn)為PATH/conf/nginx.conf。

  --error-log-path=PATH set error log pathname #錯誤文件路徑,默認(rèn)為 PATH/logs/error.log。

  --pid-path=PATH set nginx.pid pathname # master進程pid寫入的文件位置,通常在var/run下,默認(rèn)為 PATH/logs/nginx.pid。

  --lock-path=PATH set nginx.lock pathname #共享存儲器互斥鎖文件路徑

  --user=USER set non-privileged user for worker processes #指定程序運行時的非特權(quán)用戶

  --group=GROUP set non-privileged group for worker processes #指定程序運行時的非特權(quán)用戶組

  --build=NAME set build name #編譯名稱

  --builddir=DIR set build directory #指向編譯目錄

  --with-select_module enable select module 允許或不允許開啟SELECT模式,如果configure沒有找到合適的模式,比如,kqueue(sun os)、epoll(linux kenel 2.6+)、rtsig(實時信號)

  --without-select_module disable select module 禁用select模塊支持

  --with-poll_module enable poll module 啟用poll模塊支持(功能與select相同,與select特性相同,為一種輪詢模式,不推薦在高載環(huán)境下使用)

  --without-poll_module disable poll module 禁用poll模塊支持

  --with-threads enable thread pool support

  --with-file-aio enable file AIO support #為freeBSD4.3+和linux2.6.22+系統(tǒng)啟用異步io

  --with-ipv6 enable IPv6 support #啟用ipv6支持

  #默認(rèn)禁用的模塊

  --with-http_ssl_module enable ngx_http_ssl_module #使支持https請求,需已安裝openssl

  --with-http_v2_module enable ngx_http_v2_module #啟用HTTP V2

  --with-http_realip_module enable ngx_http_realip_module #此模塊支持顯示真實來源IP地址,主要用于NGINX做前端負載均衡服務(wù)器使用

  --with-http_addition_module enable ngx_http_addition_module #輸出過濾器,使你能夠在請求經(jīng)過一個location前或后時在該location本身添加內(nèi)容

  --with-http_xslt_module enable ngx_http_xslt_module #這個模塊是一個過濾器,它可以通過XSLT模板轉(zhuǎn)換XML應(yīng)答

  --with-http_xslt_module=dynamic enable dynamic ngx_http_xslt_module

  --with-http_image_filter_module enable ngx_http_image_filter_module #圖像過濾器,在將圖像投遞到客戶之前進行處理(需要libgd庫)

  --with-http_image_filter_module=dynamic

  enable dynamic ngx_http_image_filter_module

  --with-http_geoip_module enable ngx_http_geoip_module #創(chuàng)建基于與MaxMind GeoIP相配的客戶端地址

  --with-http_geoip_module=dynamic enable dynamic ngx_http_geoip_module

  --with-http_sub_module enable ngx_http_sub_module #這個模塊可以能夠在nginx的應(yīng)答中搜索并替換文本

  --with-http_dav_module enable ngx_http_dav_module #為文件和目錄指定權(quán)限,限制不同類型的用戶對于頁面有不同的操作權(quán)限

  --with-http_flv_module enable ngx_http_flv_module #這個模塊支持對FLV(flash)文件的拖動播放

  --with-http_mp4_module enable ngx_http_mp4_module #支持H.264/AAC文件為偽流媒體

  --with-http_gunzip_module enable ngx_http_gunzip_module #對于不支持gzip編碼的客戶,該模塊用于為客戶解壓縮預(yù)壓縮內(nèi)容