前言
Nginx作為一款高性能web服務(wù)器軟件乏苦,應(yīng)用廣泛,最近學(xué)習(xí)源碼养距,一探究原理和優(yōu)秀的設(shè)計(jì)诉探,用一個(gè)軟件那就從最基礎(chǔ)的編譯開(kāi)始吧。
預(yù)備編譯
首先下載Nginx源碼棍厌,官網(wǎng)肾胯,我下載的是nginx/1.10.3。
Nginx安裝也需要依賴庫(kù):gzip需要zlib庫(kù)定铜,rewrite需要pcre庫(kù)阳液,ssl需要opensll庫(kù)。
ubuntu下
apt-get install openssl libssl-dev ibpcre3 libpcre3-dev zlib1g-dev
編譯
運(yùn)行編譯help命令
./configure --help
--help print this message
--prefix=PATH set installation prefix
--sbin-path=PATH set nginx binary pathname
--modules-path=PATH set modules path
--conf-path=PATH set nginx.conf pathname
--error-log-path=PATH set error log pathname
--pid-path=PATH set nginx.pid pathname
--lock-path=PATH set nginx.lock pathname
--user=USER set non-privileged user for
worker processes
--group=GROUP set non-privileged group for
worker processes
...
這很長(zhǎng)的就是編譯參數(shù)揣炕,根據(jù)編譯參數(shù)能自定義安裝模塊和路徑。
編譯命令
./configure --add-module=/opt/app/nginx-1.10.3/addon/echo1 \
--add-module=/opt/app/nginx-1.10.3/addon/echo2 \
--add-module=/opt/app/nginx-1.10.3/addon/hello \
--add-module=/opt/app/nginx-1.10.3/addon/my1 \
--user=nginx \
--group=nginx
編譯命令可以寫(xiě)很多东跪,根據(jù)自己的需要來(lái)畸陡。
接下就是make && make install
事項(xiàng)點(diǎn)
make時(shí)可能會(huì)出現(xiàn)如下警告而退出make
src/http/ngx_http_parse.c: In function 'ngx_http_parse_complex_uri':
src/http/ngx_http_parse.c:1384:32: warning: this statement may fall through [-Wimplicit-fallthrough=]
1384 | r->plus_in_uri = 1;
| ~~~~~~~~~~~~~~~^~~
src/http/ngx_http_parse.c:1385:13: note: here
1385 | default:
| ^~~~~~~
src/http/ngx_http_parse.c:1425:32: warning: this statement may fall through [-Wimplicit-fallthrough=]
1425 | r->plus_in_uri = 1;
| ~~~~~~~~~~~~~~~^~~
src/http/ngx_http_parse.c:1426:13: note: here
1426 | default:
| ^~~~~~~
src/http/ngx_http_parse.c:1472:32: warning: this statement may fall through [-Wimplicit-fallthrough=]
1472 | r->plus_in_uri = 1;
| ~~~~~~~~~~~~~~~^~~
解決辦法:在目錄auto/gcc文件下找到174-178行刪除-Werror
# stop on warning
CFLAGS="$CFLAGS -Werror"
# debug
CFLAGS="$CFLAGS -g"