從原始碼建置 nginx
建置是使用 configure
命令配置的。它定義了系統的各個方面,包括 nginx 被允許使用的連線處理方法。最後它會建立一個 Makefile
。
configure
命令支援以下參數
-
--help
- 列印說明訊息。
-
--prefix=
路徑
- 定義一個目錄,該目錄將保存伺服器檔案。這個相同的目錄也將用於
configure
設定的所有相對路徑(除了程式庫原始碼的路徑)和nginx.conf
設定檔中。預設值設定為/usr/local/nginx
目錄。 -
--sbin-path=
路徑
- 設定 nginx 可執行檔的名稱。此名稱僅在安裝期間使用。預設情況下,該檔案名為
。prefix
/sbin/nginx -
--modules-path=
路徑
- 定義將安裝 nginx 動態模組的目錄。預設情況下,使用
目錄。prefix
/modules -
--conf-path=
路徑
- 設定
nginx.conf
設定檔的名稱。如果需要,nginx 始終可以使用不同的設定檔啟動,方法是在命令列參數中指定它 。預設情況下,該檔案名為-c
檔案
。prefix
/conf/nginx.conf -
--error-log-path=
路徑
- 設定主要錯誤、警告和診斷檔案的名稱。安裝後,始終可以使用
nginx.conf
設定檔中的 error_log 指令來變更檔名。預設情況下,該檔案名為
。prefix
/logs/error.log -
--pid-path=
路徑
- 設定將儲存主要處理程序的處理程序 ID 的
nginx.pid
檔案的名稱。安裝後,始終可以使用nginx.conf
設定檔中的 pid 指令來變更檔名。預設情況下,該檔案名為
。prefix
/logs/nginx.pid -
--lock-path=
路徑
- 設定鎖定檔案名稱的字首。安裝後,始終可以使用
nginx.conf
設定檔中的 lock_file 指令來變更值。預設值為
。prefix
/logs/nginx.lock
-
--user=
名稱
- 設定一個非特權使用者的名稱,其憑證將由工作處理程序使用。安裝後,始終可以使用
nginx.conf
設定檔中的 user 指令來變更名稱。預設的使用者名稱為 nobody。 -
--group=
名稱
- 設定一個群組的名稱,其憑證將由工作處理程序使用。安裝後,始終可以使用
nginx.conf
設定檔中的 user 指令來變更名稱。預設情況下,群組名稱設定為非特權使用者的名稱。
-
--build=
名稱
- 設定一個可選的 nginx 建置名稱。
-
--builddir=
路徑
- 設定一個建置目錄。
-
--with-select_module
--without-select_module
- 啟用或停用建置允許伺服器使用
select()
方法的模組。如果平台似乎不支援更適當的方法(例如 kqueue、epoll 或 /dev/poll),則會自動建置此模組。 -
--with-poll_module
--without-poll_module
- 啟用或停用建置允許伺服器使用
poll()
方法的模組。如果平台似乎不支援更適當的方法(例如 kqueue、epoll 或 /dev/poll),則會自動建置此模組。 -
--with-threads
- 啟用 執行緒集區 的使用。
-
--with-file-aio
- 在 FreeBSD 和 Linux 上啟用 非同步檔案 I/O (AIO) 的使用。
-
--with-http_ssl_module
- 啟用建置一個模組,該模組將 HTTPS 協定支援新增至 HTTP 伺服器。預設情況下不建置此模組。需要 OpenSSL 程式庫才能建置和執行此模組。
-
--with-http_v2_module
- 啟用建置一個模組,該模組提供 HTTP/2 的支援。預設情況下不建置此模組。
-
--with-http_v3_module
- 啟用建置一個模組,該模組提供 HTTP/3 的支援。預設情況下不建置此模組。建議使用提供 HTTP/3 支援的 SSL 程式庫來建置和執行此模組,例如 BoringSSL、LibreSSL 或 QuicTLS。否則,如果使用 OpenSSL 程式庫,則將使用不支援 QUIC early data 的 OpenSSL 相容性層。
-
--with-http_realip_module
- 啟用建置 ngx_http_realip_module 模組,該模組將用戶端位址變更為在指定的標頭欄位中傳送的位址。預設情況下不建置此模組。
-
--with-http_addition_module
- 啟用建置 ngx_http_addition_module 模組,該模組在回應前後新增文字。預設情況下不建置此模組。
-
--with-http_xslt_module
--with-http_xslt_module=dynamic
- 啟用建置 ngx_http_xslt_module 模組,該模組使用一個或多個 XSLT 樣式表轉換 XML 回應。預設情況下不建置此模組。需要 libxml2 和 libxslt 程式庫才能建置和執行此模組。
-
--with-http_image_filter_module
--with-http_image_filter_module=dynamic
- 啟用建置 ngx_http_image_filter_module 模組,該模組會轉換 JPEG、GIF、PNG 和 WebP 格式的影像。預設情況下不建置此模組。
-
--with-http_geoip_module
--with-http_geoip_module=dynamic
- 啟用建置 ngx_http_geoip_module 模組,該模組會根據用戶端 IP 位址和預先編譯的 MaxMind 資料庫建立變數。預設情況下不建置此模組。
-
--with-http_sub_module
- 啟用建置 ngx_http_sub_module 模組,該模組會透過將一個指定的字串取代為另一個字串來修改回應。預設情況下不建置此模組。
-
--with-http_dav_module
- 啟用建置 ngx_http_dav_module 模組,該模組透過 WebDAV 協定提供檔案管理自動化。預設情況下不建置此模組。
-
--with-http_flv_module
- 啟用建置 ngx_http_flv_module 模組,該模組為 Flash Video (FLV) 檔案提供虛擬串流伺服器端支援。預設情況下不建置此模組。
-
--with-http_mp4_module
- 啟用建置 ngx_http_mp4_module 模組,該模組為 MP4 檔案提供虛擬串流伺服器端支援。預設情況下不建置此模組。
-
--with-http_gunzip_module
- 啟用建置 ngx_http_gunzip_module 模組,該模組會針對不支援「gzip」編碼方法的用戶端解壓縮具有「
Content-Encoding: gzip
」的回應。預設情況下不建置此模組。 -
--with-http_gzip_static_module
- 啟用建置 ngx_http_gzip_static_module 模組,該模組允許傳送具有「
.gz
」副檔名的預先壓縮檔案,而不是常規檔案。預設情況下不建置此模組。 -
--with-http_auth_request_module
- 啟用建置 ngx_http_auth_request_module 模組,該模組根據子要求結果實作用戶端授權。預設情況下不建置此模組。
-
--with-http_random_index_module
- 啟用建置 ngx_http_random_index_module 模組,該模組處理以斜線字元 ('
/
') 結尾的要求,並在目錄中選取一個隨機檔案作為索引檔案。預設情況下不建置此模組。 -
--with-http_secure_link_module
- 啟用建置 ngx_http_secure_link_module 模組。預設情況下不建置此模組。
-
--with-http_degradation_module
- 啟用建置
ngx_http_degradation_module
模組。預設情況下不建置此模組。 -
--with-http_slice_module
- 啟用建置 ngx_http_slice_module 模組,該模組將要求分割為子要求,每個子要求都傳回特定範圍的回應。此模組提供更有效的大回應快取。預設情況下不建置此模組。
-
--with-http_stub_status_module
- 啟用建置 ngx_http_stub_status_module 模組,該模組提供對基本狀態資訊的存取。預設情況下不建置此模組。
-
--without-http_charset_module
- 停用建置 ngx_http_charset_module 模組,該模組會將指定的字元集新增至「Content-Type」回應標頭欄位,並且還可以將資料從一個字元集轉換為另一個字元集。
-
--without-http_gzip_module
- 停用建置 壓縮 HTTP 伺服器回應的模組。需要 zlib 程式庫才能建置和執行此模組。
-
--without-http_ssi_module
- 停用建置 ngx_http_ssi_module 模組,該模組會處理通過它的回應中的 SSI (伺服器端包含) 命令。
-
--without-http_userid_module
- 停用建置 ngx_http_userid_module 模組,該模組會設定適用於用戶端識別的 Cookie。
-
--without-http_access_module
- 停用建置 ngx_http_access_module 模組,該模組允許限制對特定用戶端位址的存取。
-
--without-http_auth_basic_module
- 停用建置 ngx_http_auth_basic_module 模組,該模組允許透過使用「HTTP 基本驗證」協定驗證使用者名稱和密碼來限制對資源的存取。
-
--without-http_mirror_module
- 停用建置 ngx_http_mirror_module 模組,該模組透過建立背景鏡像子要求來實作原始要求的鏡像。
-
--without-http_autoindex_module
- 停用建置 ngx_http_autoindex_module 模組。此模組處理以斜線字元(「
/
」)結尾的請求,並在 ngx_http_index_module 模組找不到索引檔時產生目錄列表。 -
--without-http_geo_module
- 停用建置 ngx_http_geo_module 模組。此模組會根據客戶端 IP 位址建立變數。
-
--without-http_map_module
- 停用建置 ngx_http_map_module 模組。此模組會根據其他變數的值建立變數。
-
--without-http_split_clients_module
- 停用建置 ngx_http_split_clients_module 模組。此模組會建立用於 A/B 測試的變數。
-
--without-http_referer_module
- 停用建置 ngx_http_referer_module 模組。此模組可以阻擋「Referer」標頭欄位中具有無效值的請求存取網站。
-
--without-http_rewrite_module
- 停用建置允許 HTTP 伺服器 重新導向請求並變更請求 URI 的模組。建置和執行此模組需要 PCRE 程式庫。
-
--without-http_proxy_module
- 停用建置 HTTP 伺服器 代理模組。
-
--without-http_fastcgi_module
- 停用建置 ngx_http_fastcgi_module 模組。此模組將請求傳遞到 FastCGI 伺服器。
-
--without-http_uwsgi_module
- 停用建置 ngx_http_uwsgi_module 模組。此模組將請求傳遞到 uwsgi 伺服器。
-
--without-http_scgi_module
- 停用建置 ngx_http_scgi_module 模組。此模組將請求傳遞到 SCGI 伺服器。
-
--without-http_grpc_module
- 停用建置 ngx_http_grpc_module 模組。此模組將請求傳遞到 gRPC 伺服器。
-
--without-http_memcached_module
- 停用建置 ngx_http_memcached_module 模組。此模組從 memcached 伺服器取得回應。
-
--without-http_limit_conn_module
- 停用建置 ngx_http_limit_conn_module 模組。此模組限制每個金鑰的連線數,例如來自單一 IP 位址的連線數。
-
--without-http_limit_req_module
- 停用建置 ngx_http_limit_req_module 模組。此模組限制每個金鑰的請求處理速率,例如來自單一 IP 位址的請求處理速率。
-
--without-http_empty_gif_module
- 停用建置 發出單像素透明 GIF 的模組。
-
--without-http_browser_module
- 停用建置 ngx_http_browser_module 模組。此模組會建立其值取決於「User-Agent」請求標頭欄位的變數。
-
--without-http_upstream_hash_module
- 停用建置實作 雜湊負載平衡方法的模組。
-
--without-http_upstream_ip_hash_module
- 停用建置實作 ip_hash 負載平衡方法的模組。
-
--without-http_upstream_least_conn_module
- 停用建置實作 最少連線負載平衡方法的模組。
-
--without-http_upstream_random_module
- 停用建置實作 隨機負載平衡方法的模組。
-
--without-http_upstream_keepalive_module
- 停用建置提供上游伺服器 連線快取的模組。
-
--without-http_upstream_zone_module
- 停用建置使上游群組的執行階段狀態能夠儲存在共用記憶體區域中的模組。
-
--with-http_perl_module
--with-http_perl_module=dynamic
- 啟用建置 內嵌 Perl 模組。預設不會建置此模組。
-
--with-perl_modules_path=
path
- 定義將保留 Perl 模組的目錄。
-
--with-perl=
path
- 設定 Perl 二進位檔的名稱。
-
--http-log-path=
path
- 設定 HTTP 伺服器的主要請求日誌檔的名稱。安裝後,可以使用 access_log 指令在
nginx.conf
組態檔中隨時變更檔案名稱。預設情況下,檔案名稱為
。prefix
/logs/access.log -
--http-client-body-temp-path=
path
- 定義用於儲存保存客戶端請求主體的暫存檔的目錄。安裝後,可以使用 client_body_temp_path 指令在
nginx.conf
組態檔中隨時變更目錄。預設情況下,目錄名稱為
。prefix
/client_body_temp -
--http-proxy-temp-path=
path
- 定義用於儲存從代理伺服器接收的資料的暫存檔的目錄。安裝後,可以使用 proxy_temp_path 指令在
nginx.conf
組態檔中隨時變更目錄。預設情況下,目錄名稱為
。prefix
/proxy_temp -
--http-fastcgi-temp-path=
path
- 定義用於儲存從 FastCGI 伺服器接收的資料的暫存檔的目錄。安裝後,可以使用 fastcgi_temp_path 指令在
nginx.conf
組態檔中隨時變更目錄。預設情況下,目錄名稱為
。prefix
/fastcgi_temp -
--http-uwsgi-temp-path=
path
- 定義用於儲存從 uwsgi 伺服器接收的資料的暫存檔的目錄。安裝後,可以使用 uwsgi_temp_path 指令在
nginx.conf
組態檔中隨時變更目錄。預設情況下,目錄名稱為
。prefix
/uwsgi_temp -
--http-scgi-temp-path=
path
- 定義用於儲存從 SCGI 伺服器接收的資料的暫存檔的目錄。安裝後,可以使用 scgi_temp_path 指令在
nginx.conf
組態檔中隨時變更目錄。預設情況下,目錄名稱為
。prefix
/scgi_temp
-
--without-http
- 停用 HTTP 伺服器。
-
--without-http-cache
- 停用 HTTP 快取。
-
--with-mail
--with-mail=dynamic
- 啟用 POP3/IMAP4/SMTP 郵件代理伺服器。
-
--with-mail_ssl_module
- 啟用建置將 SSL/TLS 協定支援新增至郵件代理伺服器的模組。預設不會建置此模組。建置和執行此模組需要 OpenSSL 程式庫。
-
--without-mail_pop3_module
- 停用郵件代理伺服器中的 POP3 協定。
-
--without-mail_imap_module
- 停用郵件代理伺服器中的 IMAP 協定。
-
--without-mail_smtp_module
- 停用郵件代理伺服器中的 SMTP 協定。
-
--with-stream
--with-stream=dynamic
- 啟用建置用於通用 TCP/UDP 代理和負載平衡的 串流模組。預設不會建置此模組。
-
--with-stream_ssl_module
- 啟用建置將 SSL/TLS 協定支援新增至串流模組的模組。預設不會建置此模組。建置和執行此模組需要 OpenSSL 程式庫。
-
--with-stream_realip_module
- 啟用建置 ngx_stream_realip_module 模組。此模組會將客戶端位址變更為在 PROXY 協定標頭中傳送的位址。預設不會建置此模組。
-
--with-stream_geoip_module
--with-stream_geoip_module=dynamic
- 啟用建置 ngx_stream_geoip_module 模組。此模組會根據客戶端 IP 位址和預先編譯的 MaxMind 資料庫建立變數。預設不會建置此模組。
-
--with-stream_ssl_preread_module
- 啟用建置 ngx_stream_ssl_preread_module 模組。此模組允許從 ClientHello 訊息中擷取資訊,而無需終止 SSL/TLS。預設不會建置此模組。
-
--without-stream_limit_conn_module
- 停用建置 ngx_stream_limit_conn_module 模組。此模組限制每個金鑰的連線數,例如來自單一 IP 位址的連線數。
-
--without-stream_access_module
- 停用建置 ngx_stream_access_module 模組。此模組允許限制對某些客戶端位址的存取。
-
--without-stream_geo_module
- 停用建置 ngx_stream_geo_module 模組。此模組會根據客戶端 IP 位址建立變數。
-
--without-stream_map_module
- 停用建置 ngx_stream_map_module 模組。此模組會根據其他變數的值建立變數。
-
--without-stream_split_clients_module
- 停用建置 ngx_stream_split_clients_module 模組。此模組會建立用於 A/B 測試的變數。
-
--without-stream_return_module
- 停用建置 ngx_stream_return_module 模組。此模組會將一些指定的值傳送至客戶端,然後關閉連線。
-
--without-stream_set_module
- 停用建置 ngx_stream_set_module 模組。此模組會設定變數的值。
-
--without-stream_upstream_hash_module
- 停用建置實作 雜湊負載平衡方法的模組。
-
--without-stream_upstream_least_conn_module
- 停用建置實作 最少連線負載平衡方法的模組。
-
--without-stream_upstream_random_module
- 停用建置實作 隨機負載平衡方法的模組。
-
--without-stream_upstream_zone_module
- 停用建置使上游群組的執行階段狀態能夠儲存在共用記憶體區域中的模組。
-
--with-google_perftools_module
- 啟用建置 ngx_google_perftools_module 模組。此模組使用 Google Performance Tools 啟用 nginx 工作進程的分析。此模組適用於 nginx 開發人員,預設不會建置。
-
--with-cpp_test_module
- 啟用建置
ngx_cpp_test_module
模組。
-
--add-module=
path
- 啟用外部模組。
-
--add-dynamic-module=
path
- 啟用外部動態模組。
-
--with-compat
- 啟用動態模組相容性。
-
--with-cc=
path
- 設定 C 編譯器的名稱。
-
--with-cpp=
path
- 設定 C 前處理器的名稱。
-
--with-cc-opt=
parameters
- 設定將新增至 CFLAGS 變數的其他參數。在 FreeBSD 下使用系統 PCRE 程式庫時,應指定
--with-cc-opt="-I /usr/local/include"
。如果需要增加select()
支援的檔案數量,也可以在此處指定,例如:--with-cc-opt="-D FD_SETSIZE=2048"
。 -
--with-ld-opt=
parameters
- 設定將在連結期間使用的其他參數。在 FreeBSD 下使用系統 PCRE 程式庫時,應指定
--with-ld-opt="-L /usr/local/lib"
。 -
--with-cpu-opt=
cpu
- 啟用依指定的 CPU 建置:
pentium
、pentiumpro
、pentium3
、pentium4
、athlon
、opteron
、sparc32
、sparc64
、ppc64
。
-
--without-pcre
- 停用 PCRE 程式庫的使用。
-
--with-pcre
- 強制使用 PCRE 程式庫。
-
--with-pcre=
path
- 設定 PCRE 函式庫的原始碼路徑。 需要從 PCRE 網站下載並解壓縮函式庫發行版本。 其餘部分由 nginx 的
./configure
和make
完成。 此函式庫是為了在 location 指令以及 ngx_http_rewrite_module 模組中支援正規表示式所必需的。 -
--with-pcre-opt=
參數
- 設定 PCRE 的額外建置選項。
-
--with-pcre-jit
- 使用「即時編譯」支援來建置 PCRE 函式庫 (1.1.12,pcre_jit 指令)。
-
--without-pcre2
- 停用使用 PCRE2 函式庫,改用原始 PCRE 函式庫 (1.21.5)。
-
--with-zlib=
路徑
- 設定 zlib 函式庫的原始碼路徑。 需要從 zlib 網站下載並解壓縮函式庫發行版本。 其餘部分由 nginx 的
./configure
和make
完成。 此函式庫是為了 ngx_http_gzip_module 模組所必需的。 -
--with-zlib-opt=
參數
- 設定 zlib 的額外建置選項。
-
--with-zlib-asm=
cpu
- 啟用使用針對指定 CPU 優化的 zlib 組譯器原始碼:
pentium
、pentiumpro
。
-
--with-libatomic
- 強制使用 libatomic_ops 函式庫。
-
--with-libatomic=
路徑
- 設定 libatomic_ops 函式庫的原始碼路徑。
-
--with-openssl=
路徑
- 設定 OpenSSL 函式庫的原始碼路徑。
-
--with-openssl-opt=
參數
- 設定 OpenSSL 的額外建置選項。
-
--with-debug
- 啟用偵錯日誌。
參數使用範例 (所有這些都需要輸入在同一行)
./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=../pcre2-10.39 --with-zlib=../zlib-1.3
設定完成後,nginx 會使用 make
編譯和安裝。