$ 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/nginx
nginx
裏面有四個目錄:c++
每次修改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