nginx 源码安装 mac

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.

  1. 安装最新的opensslhttps://www.openssl.org/
tar -zxvf openssl-1.0.2l.tar.gz
  1. 在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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容