## centos下yum安裝
nginx的RPM包可以在epel中找到,但版本較老;官方制作的RPM源較新
### 官方RPM源
~~~
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/
gpgcheck=0
enabled=1
~~~
將“OS”替換為“rhel” 或“centos”,將“OSRELEASE” 替換為“6” 或 “7”;
### [官方RPM倉庫][1]
### RPM依賴
~~~
yum install -y pcre-devel openssl-devel zlib-devel pcre zlib openssl
~~~
### 安裝
~~~
yum install -y nginx
~~~
### rpm編譯參數
[編譯時默認支持的模塊][2]
[編譯時默認不支持的模塊][3]
[第三方模塊][4]
`nginx -V`
~~~
--user=nginx
--group=nginx
--prefix=/etc/nginx
--sbin-path=/usr/sbin/nginx
--modules-path=/usr/lib64/nginx/modules
--conf-path=/etc/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
--pid-path=/var/run/nginx.pid
--lock-path=/var/run/nginx.lock
--http-client-body-temp-path=/var/cache/nginx/client_temp
--http-proxy-temp-path=/var/cache/nginx/proxy_temp
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp
--http-scgi-temp-path=/var/cache/nginx/scgi_temp
--with-compat # 動態模塊兼容
--with-file-aio # 支持異步IO
--with-threads # 支持線程池
--with-http_addition_module # 在響應報文的前后增加內容
--with-http_auth_request_module # 基于 subrequest 的結果的實現客戶端授權
--with-http_dav_module
--with-http_flv_module
--with-http_mp4_module
--with-http_gunzip_module # 在客戶端不支持gzip情況下使用gunzip
--with-http_gzip_static_module # 支持壓縮
--with-http_random_index_module # 請求以/結尾,則在目錄中任選一個作為index文件
--with-http_realip_module
--with-http_secure_link_module
--with-http_slice_module # 允許將請求拆分成子請求,每個 subrequest 返回一定范圍的響應。提供更有效的緩存的大文件。
--with-http_ssl_module # 支持ssl
--with-http_stub_status_module # 提供基本的狀態信息
--with-http_sub_module # 將響應中的指定內容替換
--with-http_v2_module # 支持http2
--with-mail # 支持mail
--with-mail_ssl_module # 支持mail的ssl
--with-stream
--with-stream_realip_module
--with-stream_ssl_module
--with-stream_ssl_preread_module
--with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC'
--with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie
~~~
## centos下編譯安裝
### 下載
http://nginx.org/download/nginx-xxx.tar.gz
### 解壓
~~~
# tar xf nginx-1.12.1.tar.gz
~~~
### 建立用戶(-r 為系統用戶)
~~~
# groupadd -r -g 110 nginx
# useradd -r -g 110 -u 110 nginx
~~~
### 解決依賴關系
~~~
yum install -y pcre-devel openssl-devel zlib-devel pcre zlib openssl
~~~
### 編譯參數
~~~
--user=nginx \
--group=nginx \
--prefix=/usr/local/nginx \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--with-compat \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module
~~~
## 第三方模塊
[如何使用第三方模塊官方文檔][5]
~~~
./configure ... --add-module=/usr/build/nginx-rtmp-module
./configure ... --add-dynamic-module=/path/to/module
~~~
這里測試了[echo-nginx-module][6],目前的版本還未支持較新版本的nginx,因此使用nginx1.10.3搭配echo-nginx-module v0.60
[1]:http://nginx.org/packages/centos/
[2]:https://www.nginx.com/resources/admin-guide/installing-nginx-open-source/#modules_default
[3]:https://www.nginx.com/resources/admin-guide/installing-nginx-open-source/#modules_not_default
[4]:https://www.nginx.com/resources/admin-guide/installing-nginx-open-source/#modules_third_party
[5]:https://www.nginx.com/resources/admin-guide/installing-nginx-open-source/#modules_third_party
[6]:https://github.com/openresty/echo-nginx-module
- nginx的功能
- nginx常用變量
- Nginx內核模塊
- Nginx的事件模塊
- Nginx的HTTP模塊
- Nginx的fastcgi
- nginx的proxy
- Upstream實現后臺服務器集群
- 文件操作優化相關的配置
- Nginx模塊管理和進程管理
- 模塊管理
- 進程管理
- 針對Nginx的Linux系統優化
- Nginx如何處理一個請求
- nginx狀態信息
- Nginx工具
- Nginx限制流量
- Nginx限制用戶的并發連接數
- 配置FLV服務器
- Nginx訪問控制
- Nginx自動索引
- Nginx網頁壓縮傳輸
- 控制Nginx如何記錄日志
- Nginx改寫響應
- Nginx重寫
- 后臺Nginx記錄原始原始IP
- Nginx防盜鏈
- Nginx的https