Nginx的模塊簡介與編譯安裝示例
Nginx由內核和模塊組成,其中,內核通過查找配置文件將客戶端請求映射到對應location參數塊,而在這個location中所配置的每條參數將會啟動不同的模塊去完成相應的工作。
模塊簡介
核心模塊
說明 | |
---|---|
Main | 配置錯誤日志、進程、權限等。 |
Events | 配置epoll、kqueue、select、poll等。 |
標準http模塊
默認均被編譯的模塊,除非--without-*禁用之。
名稱 | 說明 | 禁用選項 |
---|---|---|
Core | 控制端口、location、錯誤頁、別名和其他必要配置。 | –without-http |
Access | 基于客戶端IP地址允許/拒絕Http請求。 | –without-http_access_module |
Auth Basic | Basic HTTP 認證。 | –without-http_auth_basic_module |
Auto Index | 自動為沒有索引頁面的目錄生成文件列表。 | –without-http_autoindex_module |
Browser | 翻譯”User-Agent” 字符串。 | –without-http_browser_module |
Charset | 對Web頁面重新編碼。 | –without-http_charset_module |
Empty GIF | 在內存中生成一個高1像素、寬1像素的GIF圖片,并對外提供服務。 | –without-http_empty_gif_module |
FastCGI | 提供對FastCGI的支持。 | –without-http_fastcgi_module |
Geo | 通過IP地址的鍵值對來設置配置參數。 | –without-http_geo_module |
Gzip | 支持使用Gzip壓縮響應內容。 | –without-http_gzip_module |
Headers | 可以設定任意的HTTP響應頭。 | |
Index | 控制將哪些文件作為索引頁面。 | |
Limit? Requests | 限定客戶端創建連接的頻率。 | –without-http_limit_req_module |
Limit Zone | 限定客戶端同時建立連接的最大數。從1.1.8起不再推薦使用,建議使用 Limit Conn。 | –without-http_limit_zone_module |
Limit? Conn | 通過配置參數限定客戶端的最大并發連接數。 | –without-http_limit_conn_module |
Log | 可以定制訪問日志。 | |
Map | 以鍵值對的方式設定任意配置參數。 | –without-http_map_module |
Memcached | 支持Memcached緩存技術。 | –without-http_memcached_module |
Proxy | 代理上級服務器。 | –without-http_proxy_module |
Referer | 基于RefererHTTP請求頭對請求進行過濾。 | –without-http_referer_module |
Rewrite | 使用正則表達式對請求進行重寫。 | –without-http_rewrite_module |
SCGI | 支持SCGI協議。 | –without-http_scgi_module |
Split? Clients | 基于某些條件將客戶端分類。 | –without-http_split_clients_module |
SSI | 支持服務器端的include。 | –without-http_ssi_module |
Upstream | 支持負載均衡。 | –without-http_upstream_ip_hash_module (ip_hash directive only) |
User ID | 發行用戶身份標識cookie。 | –without-http_userid_module |
uWSGI | 支持uWSGI協議。 |
擴展http模塊
這些模塊在編譯時可選,如需要,則--with-*啟用之。
說明 | 啟用選項 | |
---|---|---|
Addition | 可以為頁面追加文本。 | –with-http_addition_module |
Degradation | 允許當剩余內存較低時對某些位置的請求返回 204 或 404 狀態碼。 | –with-http_degradation_module |
Embedded Perl | 允許在配置文件中使用 Perl。 | –with-http_perl_module |
FLV | 支持 Flash視頻(Flash Streaming Video)。 | –with-http_flv_module |
GeoIP | 根據來自 MaxMind 的 GeoIP 二進制文件中的信息創建變量。 | –with-http_geoip_module |
Google? Perftools | 支持 Google 性能工具。 | –with-google_perftools_module |
Gzip? Precompression | 提供預壓縮的靜態文件。 | –with-http_gzip_static_module |
Image? Filter | 支持使用 Libgd 對圖片進行變換。 | –with-http_image_filter_module |
MP4 | 允許對 mp4 流進行尋址。 | –with-http_mp4_module |
Random? Index | 允許使目錄索引隨機化。 | –with-http_random_index_module |
Real IP | 允許將 nginx 作為后端服務器。 | –with-http_realip_module |
Secure Link | 允許通過密鑰保護指定的文件。 | –with-http_secure_link_module |
SSL | 支持 HTTPS/SSL。 | –with-http_ssl_module |
Stub Status | 提供查看服務器統計信息的能力。 | –with-http_stub_status_module |
Substitution | 可以替換頁面中的文本。 | –with-http_sub_module |
WebDAV | 支持 WebDAV 穿透。 | –with-http_dav_module |
XSLT | 允許對頁面使用 XSLT 進行后處理。 | –with-http_xslt_module |
郵件模塊
說明 | 配置參數 | |
---|---|---|
Core | 使 Nginx 能夠處理/代理 IMAP、POP3、SMTP協議。 | –with-mail? –without-mail_pop3_module? –without-mail_imap_module? –without-mail_smtp_module |
Auth | 使用 Nginx 為郵件服務進行認證。 | ? |
Proxy | 使 Nginx 能夠代理 IMAP、POP3、SMTP協議。 | ? |
SSL | 該模塊可以讓 POP3/IMAP/SMTP 使用 SSL/TLS。 | ? –with-mail_ssl_module |
Nginx編譯安裝示例
本次實驗環境:
OS:CentOS7.4
Nginx:nginx-1.14.0.tar(官網下載)
Nginx的編譯安裝過程如下:
1.解壓nginx源碼包到/usr/local
[root@windpc ~]# tar -xvf nginx-1.14.0.tar.gz -C /usr/local/
[root@windpc ~]# cd /usr/local/nginx-1.14.0
2.添加nginx用戶且該用戶不可登錄及無家目錄
[root@windpc nginx]# useradd nginx -s /sbin/nologin
-M
3.進入nginx目錄生成Makefile
我使用的編譯參數如下:
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module? --with-http_image_filter_module? --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/data/logs/nginx/access.log --error-log-path=/data/logs/nginx/error.log
查看可用參數可用使用./configure –help
參數介紹:
- 修改nginx安裝目錄到/usr/local/nginx
- 修改nginx進程用戶為nginx
- 添加ssl、realip、image_filter、gzip_static、stub_status模塊
- 修改日志文件到/data/logs/nginx目錄下
如遇到以下錯誤提示安裝對應軟件包即可:
- ./configure: error: the HTTP rewrite module requires the PCRE library.? 對應yum install pcre-devel.x86_64
- ./configure: error: SSL modules require the OpenSSL library.? 對應yum install openssl-devel.x86_64 依賴安裝的軟件包交給yum解決,不一一列出。
- ./configure: error: the HTTP image filter module requires the GD library. 對應yum install gd-devel.x86_64
總之,缺啥裝啥,直到沒有錯誤提示。
4.使用make工具依據Makefile生成二進制文件
5.makeinstall
以下是安裝結束時末尾的提示:test -d '/usr/local/nginx/logs' \
|| mkdir -p '/usr/local/nginx/logs'
test -d '/data/logs/nginx' \
|| mkdir -p '/data/logs/nginx'
test -d '/usr/local/nginx/html' \
|| cp -R html '/usr/local/nginx'
test -d '/data/logs/nginx' \
|| mkdir -p '/data/logs/nginx'
make[1]: Leaving directory `/root/nginx-1.14.0'
可以看到,安裝時會依據之前的配置自動建立路徑,所以不用提前建立那些目錄。注意即使改了log的路徑,原來的默認文件夾里也會生成一個logs目錄。
本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.www58058.com/101472