nginx源码安装,添加with-http_ssl_module, mac采坑记
首先,下载源码,解压,进nginx文件目录,运行变以前的配置,这里因为需要nginx支持https服务,故需加上--with-http_ssl_module
参数
./configure --with-http_ssl_module
- 错误1
./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
下载pcre-8.40 解压
tar -zxvf pcre-8.40.tar.gz
再次编译
./configure --with-http_ssl_module --with-pcre=../pcre-8.40
- 错误2
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
- 安装最新的opensslhttps://www.openssl.org/
tar -zxvf openssl-1.0.2l.tar.gz
- 在nginx源码中建立一个bundle目录,并把最新的OpenSSL源码复制进来
tangliang➜local/opt/nginx-1.13.1» mkdir bundle [0:06:39]
tangliang➜local/opt/nginx-1.13.1» cp -R ../openssl-1.0.2l ./bundle
3.再次运行
./configure --with-http_ssl_module --with-pcre=../pcre-8.40 --with-openssl=./bundle/openssl-1.0.2l --prefix=/usr/l
看似没问题了,那就执行下一步把
make install
- 错误3
如果运行到此错,算你运气不好(暂时只在mac上出现了,在ubuntu上能顺利通过),前面两错都得重新解决
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [objs/nginx] Error 1
make: *** [install] Error 2
执行到这里,此错事表示pcre的link阶段出错了
参考文档
需要手动配置pcre的连接文件
因为之前是直接下载的源码,对于pcre里面链接文件不好取到,所以这里用homebrew重新安装pcre(之前下载的pcre包可以删除了),(openssl不是必须的)
brew install pcre
brew install openssl
当取到最新的pcre包之后,链接文件就比较好拿到了,根据如下配置
重新生成编译文件
export KERNEL_BITS=64
./configure --with-http_ssl_module --with-openssl=./bundle/openssl-1.0.2l --prefix=/usr/local/opt/nginx --with-cc-opt='-I/usr/local/Cellar/pcre/8.40/include/' --with-ld-opt='-L/usr/local/Cellar/pcre/8.40/lib'
最后一步
make install
不出意外,这次应该是ok了
为了使用方便,再为nginx添加一个软连接
ln -s /usr/local/opt/nginx/sbin/nginx /usr/local/bin/nginx