操作系統:CentOS-7.8
nginx版本:1.18.0
一、下載源碼
訪問nginx官網,下載nginx包,http://nginx.org/en/download.html
二、安裝依賴
-
安裝gcc的c++編譯環境:yum install gcc-c++
-
安裝解析正則表達式的庫:yum install -y pcre pcre-devel
-
安裝數據壓縮函式庫:yum install -y zlib zlib-devel
-
安裝用於安全通信的庫:yum install -y openssl openssl-devel
三、編譯安裝
-
解壓nginx包:tar -xzvf nginx-1.18.0.tar.gz
-
進入編譯解壓後的目錄,進行構建:./configure 選擇需要配置的選項
可用配置如下,使用到路徑的,需要路徑先創建好
我在安裝的配置使用到了/app/nginx/temp/nginx/這個目錄,所以先創建目錄
makedir -p /app/nginx/temp/nginx/
然後執行構建腳本命令如下:
./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
可用配置如下見文末附表。
-
進行編譯,命令:make
-
進行安裝,命令:make install
-
啓動nginx,進入自己配置的prefix指定的目錄,執行命令
-
停止:./nginx -s stop
-
重新加載:./nginx -s reload
pid文件不存在、或者pid數字無效錯誤處理辦法
1.首先檢查pid目錄是否存在,上面命令構建命名配置項–pid-path,所配置的目錄,不存在則創建一個
2.如pid目錄存在,則執行命令:./nginx -c {nginx.conf的路徑}
3.重新加載nginx:./nginx -s reload
配置 | 說明 |
---|---|
–prefix= |
Nginx安裝路徑。如果沒有指定,默認爲 /usr/local/nginx。 |
–sbin-path= |
Nginx可執行文件安裝路徑。只能安裝時指定,如果沒有指定,默認爲/sbin/nginx。 |
–conf-path= |
在沒有給定-c選項下默認的nginx.conf的路徑。如果沒有指定,默認爲/conf/nginx.conf。 |
–pid-path= |
在nginx.conf中沒有指定pid指令的情況下,默認的nginx.pid的路徑。如果沒有指定,默認爲 /logs/nginx.pid。 |
–lock-path= |
nginx.lock文件的路徑。 |
–error-log-path= |
在nginx.conf中沒有指定error_log指令的情況下,默認的錯誤日誌的路徑。如果沒有指定,默認爲 /logs/error.log。 |
–http-log-path= |
在nginx.conf中沒有指定access_log指令的情況下,默認的訪問日誌的路徑。如果沒有指定,默認爲 /logs/access.log。 |
–user= | 在nginx.conf中沒有指定user指令的情況下,默認的nginx使用的用戶。如果沒有指定,默認爲 nobody。 |
–group= | 在nginx.conf中沒有指定group指令的情況下,默認的nginx使用的組。如果沒有指定,默認爲 nobody。 |
–builddir=DIR | 指定編譯的目錄 |
–with-rtsig_module | 啓用 rtsig模塊 |
–with-select_module --without-select_module | 允許或不允許開啓SELECT模式,如果 configure 沒有找到更合適的模式,比如:kqueue(sun os),epoll (linux kenel 2.6+),rtsig(實時信號)或者/dev/poll(一種類似select的模式,底層實現與SELECT基本相 同,都是採用輪訓方法) SELECT模式將是默認安裝模式 |
–with-poll_module --without-poll_module | 是否開啓poll模塊,如果configure未發現更合適的方法(如kqueue、epoll、rtsig或/dev/poll),則默認情況下啓用此模塊。 |
–with-http_ssl_module | 開啓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” 頁 |
–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 執行文件的路徑 |
–http-log-path=PATH | 設置http access日誌路徑 |
–http-client-body-temp-path=PATH | 設置http 客戶端請求體的臨時文件目錄 |
–http-proxy-temp-path=PATH | 設置http代理的臨時文件目錄 |
–http-fastcgi-temp-path=PATH | 設置http fastcgi臨時文件目錄 |
–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預處理器的路徑 |
–with-cc-opt=OPTIONS | 將添加到變量CFLAGS的其他參數。在FreeBSD中使用系統庫PCRE時,有必要用cc opt=“-I/usr/local/include”指示。如果我們使用select(),並且需要增加文件描述符的數量,那麼也可以在這裏分配:-使用cc opt=“-D FD_SETSIZE=2048”。 |
–with-ld-opt=OPTIONS | 傳遞給鏈接器的其他參數。在FreeBSD中使用系統庫PCRE時,有必要用ld opt=“-L/usr/local/lib”指示。 |
–with-cpu-opt=CPU | 爲特定的 CPU 編譯,有效的值包括:pentium,pentiumpro,pentium3,pentium4,athlon,opteron,amd64,sparc32,sparc64,ppc64 |
–without-pcre | 禁止 PCRE 庫的使用。同時也會禁止 HTTP rewrite 模塊。在 “location” 配置指令中的正則表達式也需要 PCRE。 |
–with-pcre=DIR | 指定 PCRE 庫的源代碼的路徑。 |
–with-pcre-opt=OPTIONS | 爲構建PCRE設置其他選項 |
–with-md5=DIR | 設置md5庫源的路徑 |
–with-md5-opt=OPTIONS | 爲md5構建設置其他選項 |
–with-md5-asm | 使用md5彙編程序源 |
–with-sha1=DIR | 設置sha1庫源的路徑 |
–with-sha1-opt=OPTIONS | 爲sha1構建設置其他選項。 |
–with-sha1-asm | 使用sha1彙編程序源 |
–with-zlib=DIR | 設置zlib庫源的路徑 |
–with-zlib-opt=OPTIONS | 爲zlib構建設置其他選項 |
–with-zlib-asm=CPU | 使用爲指定CPU優化的zlib彙編程序源,有效值爲:pentium、pentiumpro |
–with-openssl=DIR | 設置OpenSSL庫源的路徑 |
–with-openssl-opt=OPTIONS | 爲OpenSSL構建設置其他選項 |
–with-debug | 啓用調試日誌 |
–add-module=PATH | 在目錄路徑中添加第三方模塊 |
個人公衆號【愛做夢的錘子】,全網同id,個站 http://te-amo.site,歡迎關注,裏面會分享更多有用知識,還有我的私密照片
覺得不錯就點個贊叭QAQ