CentOs7.3 編譯安裝 Nginx 1.9.9

CentOs7.3 編譯安裝 Nginx 1.9.9

安裝

安裝依賴

$ yum install -y  gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel

下載並解壓

$ cd /opt/
$ wget http://nginx.org/download/nginx-1.9.9.tar.gz
$ tar zxvf nginx-1.9.9.tar.gz

編譯

編譯時候能夠指定編譯參數,參考文章尾部:經常使用編譯選項html

$ cd nginx-1.9.9
$ ./configure

安裝

$ make
$ make && make install

默認安裝在/usr/local/nginxnginx

裏面有四個目錄:c++

  • conf: 配置文件夾,最重要文件是nginx.conf
  • html: 靜態網頁文件夾
  • logs: 日誌文件夾
  • sbin: nginx 的可執行文件,啓動、中止等操做

經常使用命令

正確性檢查

每次修改nginx配置文件後都要進行檢查web

$ /usr/local/nginx/sbin/nginx -t
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

啓動

$ /usr/local/nginx/sbin/nginx

若是不能訪問,檢查防火牆並關閉防火牆正則表達式

centos 6.x 關閉 iptablescentos

$ service iptables status # 查詢防火牆狀態命令
$ service iptables stop # 關閉命令

centos 7.x 關閉firewall瀏覽器

$ ssystemctl status  firewalld.service # 查看狀態
$ systemctl stop firewalld.service # 中止firewall

瀏覽器輸入本機IP ,看到以下內容證實安裝成功服務器

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

中止

$ /usr/local/nginx/sbin/nginx -s stop

重啓

$ /usr/local/nginx/sbin/nginx -s reload

經常使用編譯選項

./configure \
--prefix=/home/nginx \
--sbin-path=/usr/sbin/nginx \
--user=nginx \
--group=nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/home/log/nginx/error.log \
--http-log-path=/home/log/nginx/access.log \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_realip_module \
--pid-path=/home/run/nginx.pid \
--with-pcre=/home/software/pcre-8.35 \
--with-zlib=/home/software/zlib-1.2.8 \
--with-openssl=/home/software/openssl-1.0.1i

選項說明

--prefix=/home/nginx \ Nginx安裝的根路徑,全部其它路徑都要依賴該選項
--sbin-path=/usr/sbin/nginx \ nginx的可執行文件的路徑(nginx)
--user=nginx \ worker進程運行的用戶
--group=nginx \ worker進程運行的組
--conf-path=/etc/nginx/nginx.conf \  指向配置文件(nginx.conf)
--error-log-path=/var/log/nginx/error.log \ 指向錯誤日誌目錄
--http-log-path=/var/log/nginx/access.log \  設置主請求的HTTP服務器的日誌文件的名稱
--with-http_ssl_module \  使用https協議模塊。默認狀況下,該模塊沒有被構建。前提是openssl與openssl-devel已安裝
--with-http_gzip_static_module \  啓用ngx_http_gzip_static_module支持(在線實時壓縮輸出數據流)
--with-http_stub_status_module \  啓用ngx_http_stub_status_module支持(獲取nginx自上次啓動以來的工做狀態)
--with-http_realip_module \  啓用ngx_http_realip_module支持(這個模塊容許從請求標頭更改客戶端的IP地址值,默認爲關)
--pid-path=/var/run/nginx.pid \  指向pid文件(nginx.pid)

設置PCRE庫的源碼路徑,若是已經過yum方式安裝,使用–with-pcre自動找到庫文件。使用–with-pcre=PATH時,須要從PCRE網站下載pcre庫的源碼(版本4.4 – 8.30)並解壓,剩下的就交給Nginx的./configure和make來完成。perl正則表達式使用在location指令和 ngx_http_rewrite_module模塊中。
--with-pcre=/home/software/pcre-8.35 \ 

指定 zlib(版本1.1.3 – 1.2.5)的源碼解壓目錄。在默認就啓用的網絡傳輸壓縮模塊ngx_http_gzip_module時須要使用zlib 。
--with-zlib=/home/software/zlib-1.2.8 \

指向openssl安裝目錄
--with-openssl=/home/software/openssl-1.0.1i

Contact

  • 做者:鵬磊
  • 出處:http://www.ymq.io
  • Email:admin@souyunku.com
  • 版權歸做者全部,轉載請註明出處
  • Wechat:關注公衆號,搜雲庫,專一於開發技術的研究與知識分享

關注公衆號-搜雲庫

相關文章
相關標籤/搜索