Mac搭建openresty的坑
-
openresty网站:http://openresty.org/cn/installation.html
开始以为有这个网站,应该很快搭好了,谁知道几乎搞了一天。先捋捋自己的思路吧:
1.1 开始也想着,按照这个思路做:
对于 Mac OS X 或 macOS 用户,强烈推荐您使用 homebrew 包管理工具安装 OpenResty。可以直接使用下面 这一条命令:
brew install openresty/brew/openresty
但是报错的是
curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused
原因:
解决方案:因为dns域名被污染,需要在本机hosts文件中配置ip域名映射,从https://www.ipaddress.com/网站查找raw.githubusercontent.com的国外ip地址
在hosts文件放了好几个对应的ip(自行搜索Mac如何改Hosts头)
199.232.68.133 raw.githubusercontent.com
185.199.111.133 https://raw.githubusercontent.com
199.232.4.133 raw.githubusercontent.com
但没起作用!果断放弃,这条路不通,只能在本地编译代码了。
1.2 源码编译、按照
openresty-1.19.3.1.tar.gz 下载了,然后开始编译
cd openresty-VERSION/
./configure
make
sudo make install
出现的问题:
-
xcrun: error: invalid active developer path, missing xcrun的问题
解决:xcode-select --install
-
./configure: No such file or directory错误的问题
这个问题是要在openresty安装目录下,./配置文件名进行配置。
-
缺少OpenSsl library
报错如下
./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) 下载:https://www.openssl.org/source/;
发现好像没成功,然后又brew install openssl,显示已经安装,进入目录,发现没有库包(也就是lib),于是查找原因:
openssl源码中提供的config命令默认没有生成 .so,解决办法执行 ./config 时增加参数 shared
-
解决,进入目录:
./config shared
make
make install
生成了库,同时也会生成opt下的openssl文件夹,里面会生成库lib,而不是在安装目录。
最后再次configure
/configure \
--with-cc-opt="-I/usr/local/opt/openssl/include/ -I/usr/local/opt/pcre/include/" \
--with-ld-opt="-L/usr/local/opt/openssl/lib/ -L/usr/local/opt/pcre/lib/" \
-j8
看到上面的/usr/local/opt/openssl/include/
和/usr/local/opt/openssl/lib/
就更加理解了,本地编译就是要这种效果,configure是要把这些都关联起来。
于是很顺畅的就成功了,最后:
make
sudo make install
大功告成!
思路总结:
-
按brew install 的方法走不通,不知道是不是网站ip的问题;
-
走本地编译,因为不了解,走了很多弯路;一般的下载后,进入目录
./configure
,使配置生效,然后make(效果应该是编译),再安装:sudo make install(sudo 是使用root身份)
网友评论