操作系統(tǒng):CentOS-7.8
nginx版本:1.18.0
一、下載源碼
訪問(wèn)nginx官網(wǎng)阴绢,下載nginx包店乐,http://nginx.org/en/download.html
二、安裝依賴
安裝gcc的c++編譯環(huán)境:yum install gcc-c++
安裝解析正則表達(dá)式的庫(kù):yum install -y pcre pcre-devel
安裝數(shù)據(jù)壓縮函式庫(kù):yum install -y zlib zlib-devel
安裝用于安全通信的庫(kù):yum install -y openssl openssl-devel
三呻袭、編譯安裝
解壓nginx包:tar -xzvf nginx-1.18.0.tar.gz
進(jìn)入編譯解壓后的目錄眨八,進(jìn)行構(gòu)建:./configure 選擇需要配置的選項(xiàng)
可用配置如下,<font color=#00bfa5>使用到路徑的左电,需要路徑先創(chuàng)建好</font>
我在安裝的配置使用到了/app/nginx/temp/nginx/這個(gè)目錄廉侧,所以先創(chuàng)建目錄
makedir -p /app/nginx/temp/nginx/
然后執(zhí)行構(gòu)建腳本命令如下:
./configure \
--prefix=/app/nginx/local/nginx \
--pid-path=/app/nginx/run/nginx/nginx.pid \
--lock-path=/app/nginx/lock/nginx.lock \
--error-log-path=/app/nginx/log/nginx/error.log \
--http-log-path=/app/nginx/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/app/nginx/temp/nginx/client \
--http-proxy-temp-path=/app/nginx/temp/nginx/proxy \
--http-fastcgi-temp-path=/app/nginx/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/app/nginx/temp/nginx/uwsgi \
--http-scgi-temp-path=/app/nginx/temp/nginx/scgi
可用配置如下見(jiàn)文末附表。
進(jìn)行編譯篓足,命令:make
進(jìn)行安裝段誊,命令:make install
啟動(dòng)nginx,進(jìn)入自己配置的prefix指定的目錄栈拖,執(zhí)行命令
停止:./nginx -s stop
重新加載:./nginx -s reload
pid文件不存在连舍、或者pid數(shù)字無(wú)效錯(cuò)誤處理辦法
1.首先檢查pid目錄是否存在,上面命令構(gòu)建命名配置項(xiàng)--pid-path涩哟,所配置的目錄索赏,不存在則創(chuàng)建一個(gè)
2.如pid目錄存在,則執(zhí)行命令:./nginx -c {nginx.conf的路徑}
3.重新加載nginx:./nginx -s reload
配置 | 說(shuō)明 |
---|---|
--prefix=<path> | Nginx安裝路徑贴彼。如果沒(méi)有指定潜腻,默認(rèn)為 /usr/local/nginx。 |
--sbin-path=<path> | Nginx可執(zhí)行文件安裝路徑锻弓。只能安裝時(shí)指定砾赔,如果沒(méi)有指定,默認(rèn)為<prefix>/sbin/nginx。 |
--conf-path=<path> | 在沒(méi)有給定-c選項(xiàng)下默認(rèn)的nginx.conf的路徑暴心。如果沒(méi)有指定妓盲,默認(rèn)為<prefix>/conf/nginx.conf。 |
--pid-path=<path> | 在nginx.conf中沒(méi)有指定pid指令的情況下专普,默認(rèn)的nginx.pid的路徑悯衬。如果沒(méi)有指定,默認(rèn)為 <prefix>/logs/nginx.pid檀夹。 |
--lock-path=<path> | nginx.lock文件的路徑筋粗。 |
--error-log-path=<path> | 在nginx.conf中沒(méi)有指定error_log指令的情況下,默認(rèn)的錯(cuò)誤日志的路徑炸渡。如果沒(méi)有指定娜亿,默認(rèn)為 <prefix>/logs/error.log。 |
--http-log-path=<path> | 在nginx.conf中沒(méi)有指定access_log指令的情況下蚌堵,默認(rèn)的訪問(wèn)日志的路徑买决。如果沒(méi)有指定,默認(rèn)為 <prefix>/logs/access.log吼畏。 |
--user=<user> | 在nginx.conf中沒(méi)有指定user指令的情況下督赤,默認(rèn)的nginx使用的用戶。如果沒(méi)有指定泻蚊,默認(rèn)為 nobody躲舌。 |
--group=<group> | 在nginx.conf中沒(méi)有指定group指令的情況下,默認(rèn)的nginx使用的組性雄。如果沒(méi)有指定没卸,默認(rèn)為 nobody。 |
--builddir=DIR | 指定編譯的目錄 |
--with-rtsig_module | 啟用 rtsig模塊 |
--with-select_module --without-select_module | 允許或不允許開(kāi)啟SELECT模式秒旋,如果 configure 沒(méi)有找到更合適的模式办悟,比如:kqueue(sun os),epoll (linux kenel 2.6+),rtsig(實(shí)時(shí)信號(hào))或者/dev/poll(一種類似select的模式,底層實(shí)現(xiàn)與SELECT基本相 同滩褥,都是采用輪訓(xùn)方法) SELECT模式將是默認(rèn)安裝模式 |
--with-poll_module --without-poll_module | 是否開(kāi)啟poll模塊病蛉,如果configure未發(fā)現(xiàn)更合適的方法(如kqueue、epoll瑰煎、rtsig或/dev/poll)铺然,則默認(rèn)情況下啟用此模塊。 |
--with-http_ssl_module | 開(kāi)啟HTTP SSL模塊 |
--with-http_realip_module | 啟用 ngx_http_realip_module |
--with-http_addition_module | 啟用 ngx_http_addition_module |
--with-http_sub_module | 啟用 ngx_http_sub_module |
--with-http_dav_module | 啟用 ngx_http_dav_module |
--with-http_flv_module | 啟用 ngx_http_flv_module |
--with-http_stub_status_module | 啟用 "server status" 頁(yè) |
--without-http_charset_module | 禁用 ngx_http_charset_module |
--without-http_gzip_module | 禁用 ngx_http_gzip_module. 如果啟用酒甸,需要 zlib魄健。 |
--without-http_ssi_module | 禁用 ngx_http_ssi_module |
--without-http_userid_module | 禁用 ngx_http_userid_module |
--without-http_access_module | 禁用 ngx_http_access_module |
--without-http_auth_basic_module | 禁用 ngx_http_auth_basic_module |
--without-http_autoindex_module | 禁用 ngx_http_autoindex_module |
--without-http_geo_module | 禁用 ngx_http_geo_module |
--without-http_map_module | 禁用 ngx_http_map_module |
--without-http_referer_module | 禁用 ngx_http_referer_module |
--without-http_rewrite_module | 禁用 ngx_http_rewrite_module. 如果啟用需要 PCRE。 |
--without-http_proxy_module | 禁用 ngx_http_proxy_module |
--without-http_fastcgi_module | 禁用 ngx_http_fastcgi_module |
--without-http_memcached_module | 禁用 ngx_http_memcached_module |
--without-http_limit_zone_module | 禁用 ngx_http_limit_zone_module |
--without-http_empty_gif_module | 禁用 ngx_http_empty_gif_module |
--without-http_browser_module | 禁用 ngx_http_browser_module |
--without-http_upstream_ip_hash_module | 禁用 ngx_http_upstream_ip_hash_module |
--with-http_perl_module | 啟用 ngx_http_perl_module |
--with-perl_modules_path=PATH | 指定 perl模塊的路徑 |
--with-perl=PATH | 指定 perl 執(zhí)行文件的路徑 |
--http-log-path=PATH | 設(shè)置http access日志路徑 |
--http-client-body-temp-path=PATH | 設(shè)置http 客戶端請(qǐng)求體的臨時(shí)文件目錄 |
--http-proxy-temp-path=PATH | 設(shè)置http代理的臨時(shí)文件目錄 |
--http-fastcgi-temp-path=PATH | 設(shè)置http fastcgi臨時(shí)文件目錄 |
--without-http | 禁用 HTTP server |
--with-mail | 啟用 IMAP4/POP3/SMTP 代理模塊 |
--with-mail_ssl_module | 啟用 ngx_mail_ssl_module |
--with-cc=PATH | 指定 C編譯器的路徑 |
--with-cpp=PATH | 指定 C預(yù)處理器的路徑 |
--with-cc-opt=OPTIONS | 將添加到變量CFLAGS的其他參數(shù)插勤。在FreeBSD中使用系統(tǒng)庫(kù)PCRE時(shí)沽瘦,有必要用cc opt=“-I/usr/local/include”指示革骨。如果我們使用select(),并且需要增加文件描述符的數(shù)量析恋,那么也可以在這里分配:-使用cc opt=“-D FD_SETSIZE=2048”良哲。 |
--with-ld-opt=OPTIONS | 傳遞給鏈接器的其他參數(shù)。在FreeBSD中使用系統(tǒng)庫(kù)PCRE時(shí)助隧,有必要用ld opt=“-L/usr/local/lib”指示筑凫。 |
--with-cpu-opt=CPU | 為特定的 CPU 編譯,有效的值包括:pentium,pentiumpro,pentium3,pentium4,athlon,opteron,amd64,sparc32,sparc64,ppc64 |
--without-pcre | 禁止 PCRE 庫(kù)的使用并村。同時(shí)也會(huì)禁止 HTTP rewrite 模塊巍实。在 "location" 配置指令中的正則表達(dá)式也需要 PCRE。 |
--with-pcre=DIR | 指定 PCRE 庫(kù)的源代碼的路徑哩牍。 |
--with-pcre-opt=OPTIONS | 為構(gòu)建PCRE設(shè)置其他選項(xiàng) |
--with-md5=DIR | 設(shè)置md5庫(kù)源的路徑 |
--with-md5-opt=OPTIONS | 為md5構(gòu)建設(shè)置其他選項(xiàng) |
--with-md5-asm | 使用md5匯編程序源 |
--with-sha1=DIR | 設(shè)置sha1庫(kù)源的路徑 |
--with-sha1-opt=OPTIONS | 為sha1構(gòu)建設(shè)置其他選項(xiàng)棚潦。 |
--with-sha1-asm | 使用sha1匯編程序源 |
--with-zlib=DIR | 設(shè)置zlib庫(kù)源的路徑 |
--with-zlib-opt=OPTIONS | 為zlib構(gòu)建設(shè)置其他選項(xiàng) |
--with-zlib-asm=CPU | 使用為指定CPU優(yōu)化的zlib匯編程序源,有效值為:pentium膝昆、pentiumpro |
--with-openssl=DIR | 設(shè)置OpenSSL庫(kù)源的路徑 |
--with-openssl-opt=OPTIONS | 為OpenSSL構(gòu)建設(shè)置其他選項(xiàng) |
--with-debug | 啟用調(diào)試日志 |
--add-module=PATH | 在目錄路徑中添加第三方模塊 |
個(gè)人公眾號(hào)【愛(ài)做夢(mèng)的錘子】瓦盛,全網(wǎng)同id,個(gè)站 http://te-amo.site外潜,歡迎關(guān)注,里面會(huì)分享更多有用知識(shí)挠唆,還有我的私密照片
覺(jué)得不錯(cuò)就點(diǎn)個(gè)贊叭QAQ