日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

nginx安装及编译参数详解

發布時間:2025/4/16 编程问答 51 豆豆
生活随笔 收集整理的這篇文章主要介紹了 nginx安装及编译参数详解 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.centos下Yum安裝 Nginx
yum list|grep nginx 發現沒有可用的結果
通過創建下面的文件在系統中添加nginx倉庫的yum配置
vi /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1
wq!
然后
yum list|grep nginx
[root@localhost110 nginx-1.8.0]# yum list|grep nginx
nginx.x86_64 1.8.1-1.el6.ngx nginx
nginx-debug.x86_64 1.8.0-1.el6.ngx nginx
nginx-debuginfo.x86_64 1.8.1-1.el6.ngx nginx
nginx-nr-agent.noarch 2.0.0-9.el6.ngx nginx
就可以用yum install nginx來安裝了

2.源碼方式安裝
Nginx代碼提供2個獨立的下載分支,標準版和開發版
開發分支是一個處于積極開發狀態的版本,都可以用于生產環境,主要區別在于對第三方模塊的支持
在開發版本內部的api可能會發生改變,而標準版的卻保持不變
因此,為了向下兼容第三方模塊,在標準版中第三方模塊都可以有效使用
下載源碼包,解壓 編譯安裝即可

編譯通用配置選項見下表

選項

解釋說明

--prefix=<path>

Nginx安裝的根路徑,所有其它路徑都要依賴該選項

--sbin-path=<path>

指定nginx二進制文件的路徑,沒指定的話?這個路徑依賴--prefix選項

--conf-path=<path>

如果在命令行未指定配置文件,那么將會通過這里指定的路徑,nginx將會去那里查找他的配置文件

--error-log-path=<path>

錯誤文件路徑,nginx寫入錯誤日志文件地址,除非有其他配置

--pid-path=<path>

nginx?master進程pid寫入的文件位置,通常在var/run下

--lock-path=<path>

共享存儲器互斥鎖文件路徑

--user=<user>

worker進程運行的用戶

--group=<group>

worker進程運行的組

--with-file-aio.

為freeBSD4.3+和linux2.6.22+系統啟用異步io

--width-debug

啟用調試日志,生產環境不推薦

nginx -V ?查看編譯參數

nginx version: nginx/1.8.1 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC) built with OpenSSL 1.0.1e-fips 11 Feb 2013 TLS SNI support enabled configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --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 --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_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_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_spdy_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'

即為

--prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --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 --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_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_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_spdy_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'

優化編譯參數 見下表

選項

說明

--with-cc=<path>

如果想設置一個不在默認path下的c編譯器

--with-cpp=<path>

設置c預處理器的相對路徑

--with-cc-opt=<options>

指定必要的include文件路徑,可能d(-I<path>)指出,也可能是優化(-O4)和指定一個64位構建????(完全看不懂啊)

--with-ld-opt=<options>

包含連接庫的路徑和運行路徑

-with-cpu-opt=<cpu>

通過該選項為特定cpu構建nginx

?

郵件模塊獨有的配置選項

選項

? ? ? ? ? ? ? ? ?說明

--with-mail

激活POP3/IMAP4/SMTP代理模塊,默認未激活

--with-mail_ssl_module

允許ngx_mail_ssl_module模塊

這個模塊使得POP3IMAPSMTP可以使用SSLTLS.配置已經定義了HTTP?SSL模塊,但是不支持客戶端證書檢測

--without-mail_pop3_module

啟用mail模塊后,單獨禁用pop3模塊

--without-mail_imap_module

啟用mail模塊后,單獨禁用imap模塊

--without-mail_smtp_module

啟用mail模塊后,單獨禁用smtp模塊

--without-http?

完全禁用http模塊,如果只想支持mall,可以使用此項設置

--with-openssl=DIR?

設定OpenSSL庫文件路徑

對于典型的mail代理,nginx配置可為

./configure?--with-mail??--with-mail_ssl_module??--with-openssl=${BUILD_DIR}/openssl-1.0.1c

指定路徑的配置選項

下邊顯示了http模塊有效的配置選項,從激活perl模塊到臨時目錄的位置

?

選項

說明

--without-http-cache

在使用upstream模塊時,nginx能夠配置本地緩存內容,此選項可禁用緩存

--with-http_perl_module

這個模塊允許nginx使用SSI調用perl或直接執行perl(使用會降低性能)

--with-perl_modules_path=PATH

設置perl模塊路徑(perl解析器路徑)

--with-perl_modules_path=PATH

?設置perl模塊路徑

--http-log-path=PATH?

設置access?log文件路徑

--http-client-body-temp-path=PATH?

設置客戶端請求臨時文件路徑,如果WebDAV啟用,推薦設置該路徑為同一文件系統上的目錄作為最終的目的地

--http-proxy-temp-path=PATH?

代理設置后,設置http?proxy臨時文件路徑

--http-fastcgi-temp-path=PATH?

設置http?fastcgi臨時文件路徑

--http-fastcgi-temp-path=PATH??????

set?path?to?store?http?fastcgi?temporary?files

?--http-scgi-temp-path=PATH?????????

set?path?to?store?http?scgi?temporary?files

使用各種模塊

nginx發布的版本中,除了httpmail模塊之外,還有一些其他模塊在默認安裝時并沒有被安裝

可通過以下配置來啟用相應的選項

http模塊配置選項

?

選項

說明

--with-http_ssl_module

如果需要對流量加密.可使用此選項,urls中開始部分將會是https(需要openssl)

--with-http_realip_module?

允許ngx_http_realip_module模塊(mod_rpaf)

此模塊支持顯示真實來源IP地址,主要用于NGINX做前端負載均衡服務器使用,

如果你的nginx在七層負載均衡器或者其它設備之后,它們將Http頭中的客戶端ip地址傳遞,這時需要啟用此模塊,在多個客戶處于一個ip地址的情況下使用

--with-http_addition_module?

作為一個輸出過濾器,使你能夠在請求經過一個location前或后時在該location本身添加內容

--with-http_xslt_module?

?

這個模塊是一個過濾器,它可以通過XSLT模板轉換XML應答

--with-http_image_filter_module

圖像過濾器,在將圖像投遞到客戶之前進行處理(需要libgd)

--with-http_geoip_module

使用該模塊,能夠設置設置個中變量以便在配置區段中使用

--with-http_sub_module?

允許ngx_http_sub_module模塊

這個模塊可以能夠在nginx的應答中搜索并替換文本

--with-http_dav_module?

允許ngx_http_dav_module模塊(mod_dav)

為文件和目錄指定權限,限制不同類型的用戶對于頁面有不同的操作權限

--with-http_flv_module

?

允許ngx_http_flv_module模塊(mod_flvx)

這個模塊支持對FLVflash)文件的拖動播放

--with-http_mp4_module?

支持H.264/AAC文件為偽流媒體

-with-http_gzip_static_module?

允許ngx_http_gzip_static_module模塊(mod_dflate)

這個模塊在一個預壓縮文件傳送到開啟Gzip壓縮的客戶端之前檢查是否已經存在以“.gz”結尾的壓縮文件,這樣可以防止文件被重復壓縮

??--with-http_gunzip_module?

對于不支持gzip編碼的客戶,該模塊用于為客戶解壓縮預壓縮內容

--with-http_random_index_module?

允許ngx_http_random_index_module模塊(mod_autoindex),從目錄中選擇一個隨機主頁

--with-http_secure_link_module

該模塊提供一種機制,它會將一個哈希值鏈接到一個url,因此,只有那些使用正確的密碼能夠計算鏈接

--with-http_stub_status_module

?

這個模塊可以取得一些nginx的運行狀態,如果是工業狀況,可以直接取消

輸出的狀態信息科使用RRDtool或類似的工具繪制成圖

?

?

?

?

正如上表所列,這些模塊都是建立在http模塊基礎之上的,它們提供了額外的功能。在編譯時啟用這些模塊根本不會影響到運行性能,以后再配置使用這些模塊時性能會產生影響

對于網絡加速代理,就配置選項,建議以下配置

?./configure?--with-http_ssl_module?--with-http_realip_module?--with-http_geoip_module?--with-http_stub_status_module??--with-openssl=${BUILD_DIR}/openssl-1.0.1c

web服務器

?./configure?--with-http_stub_status_module

?一個簡單的安裝

./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=/usr/local/src/pcre-8.41 \ --with-zlib=/usr/local/src/zlib-1.2.7 \ --with-openssl=/usr/local/src/openssl-1.0.1t

--with-pcre=/usr/local/src/pcre-8.41 \
--with-zlib=/usr/local/src/zlib-1.2.7 \
--with-openssl=/usr/local/src/openssl-1.0.1t

這3個是庫的源碼位置

等號左右不能有空格

未完待續

?

轉載于:https://www.cnblogs.com/HKUI/p/5225895.html

總結

以上是生活随笔為你收集整理的nginx安装及编译参数详解的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。