mac 编译openresty常见问题

第一次装openresty没有事情的,然.

第一次装openresty没有事情的,然而重装MAC后,再装openresty出现了问题。安装openresty可以直接

git clone https://github.com/openresty

下来,运行make,自动下载依赖包,也可以直接到 http://openresty.org/ 下载打包好的。

1.openssl缺少错误如下

1
2
3
4
5
6
./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.

ERROR: failed to run command: sh ./configure --prefix=/usr/local/openresty/nginx \…

缺少openssl库,那就把本机安装路径告诉它吧:

./configure —with-openssl=/usr/local/Cellar/openssl/1.0.2c

2.openssl源码安装错误

1
2
3
4
5
6
7
8
9
10
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f objs/Makefile
cd /usr/local/Cellar/openssl/1.0.2c \
	&& if [ -f Makefile ]; then /Applications/Xcode.app/Contents/Developer/usr/bin/make clean; fi \
	&& ./config --prefix=/usr/local/Cellar/openssl/1.0.2c/.openssl no-shared  no-threads \
	&& /Applications/Xcode.app/Contents/Developer/usr/bin/make \
	&& /Applications/Xcode.app/Contents/Developer/usr/bin/make install LIBDIR=lib
/bin/sh: ./config: No such file or directory
make[2]: *** [/usr/local/Cellar/openssl/1.0.2c/.openssl/include/openssl/ssl.h] Error 127
make[1]: *** [build] Error 2
make: *** [all] Error 2

上了github,https://github.com/torch/image/issues/16,查查,明白了,这里要的是source code,不是安装路径,够坑的了吧。

那么好了,到https://www.openssl.org/下载了最新的,openssl.1.0.2c版本,到bundle目录里:

export KERNEL_BITS=64
./configure --with-cc-opt='-I/usr/local/Cellar/pcre/8.36/include/' \
       --with-ld-opt='-L/usr/local/Cellar/pcre/8.36/lib' \
       --with-openssl=bundle/openssl-OpenSSL_1_0_2c -j2

报了个warning:

1
2
3
WARNING! If you wish to build 64-bit library, then you have to
         invoke './Configure darwin64-x86_64-cc' *manually*.
         You have about 5 seconds to press Ctrl-C to abort.

看着是openssl与darwin的版本不兼容问题,后来发现是新版的openssl与nginx兼容问题。

3.pcre依赖报错

1
2
3
4
5
ld: symbol(s) not found for architecture x86_64 collect2: ld 
returned 1 exit status make[2]: *** [objs/nginx] 
Error 1 make[1]: *** [build] 
Error 2 make: *** 
[all] Error 2

找一找,发现了问题解决方案,是pcre依赖包没带上,也就是正则匹配依赖包的问题了:

在github上找到了issuse相关信息: https://github.com/openresty/ngx_openresty/issues/3#issuecomment-120227290

最后在issuse上问道了agentzh的解决方案,agentzh的makefile里在处理新版nginx与openssl依赖上的一点问题,后来他更新了github仓库:

1
2
3
4
5
6
export KERNEL_BITS=64
./configure --with-cc-opt='-I/usr/local/Cellar/pcre/8.37/include/' \
       --with-ld-opt='-L/usr/local/Cellar/pcre/8.37/lib' \
       --with-openssl=$HOME/work/openssl-1.0.2d -j9
make -j9
sudo make install

在我这里(MAC OSX 10.10.4)运行起来是没问题的。

两个问题:

1.openssl依赖,要用源码,要export告诉系统环境变量

2.pcre包要手动加上去。