2018年8月31日

幫 nginx 增加 geoip 模組

原本的 nginx 使用 yum 安裝
先取得原先參數
# nginx -V

在後面加入 geoip 模組開始編譯
# ./configure ............. --with-http_geoip_module

發生錯誤
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre= option.


下載PCRE library
官網:http://www.pcre.org/
下載:https://ftp.pcre.org/pub/pcre/
# ./configure --prefix=/usr/local/web/pcre

發生錯誤
configure: error: Invalid C++ compiler or C++ compiler flags

# yum install -y gcc gcc-c++

編譯 nginx
# ./configure ............. --with-http_geoip_module --with-pcre=/usr/local/web/src/pcre-8.42/
這裡pcre路徑是原始碼路徑、非安裝路徑

出現 fPIC 錯誤
/usr/bin/ld: /usr/local/web/src/pcre-8.42/.libs/libpcre.a(libpcre_la-pcre_compile.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/local/web/src/pcre-8.42/.libs/libpcre.a: could not read symbols: Bad value
collect2: ld returned 1 exit status


編輯 objs/Makefile 裡面的 CFLAGS 參數,加入 -fPIC
/usr/local/web/src/pcre-8.42/Makefile: objs/Makefile
cd /usr/local/web/src/pcre-8.42 \
&& if [ -f Makefile ]; then $(MAKE) distclean; fi \
&& CC="$(CC)" CFLAGS="-fPIC -O2 -fomit-frame-pointer -pipe " \
./configure --disable-shared


# make && make install

0 意見:

張貼留言