openresty环境搭建问题记录
Posted SonoFelice——棣琦
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了openresty环境搭建问题记录相关的知识,希望对你有一定的参考价值。
第一次在mac安装遇到如下问题:
截图:
具体code如下:
Sonofelice:bch-flowrouter baidu$ brew install openresty/brew/openresty Updating Homebrew... ==> Homebrew has enabled anonymous aggregate user behaviour analytics. Read the analytics documentation (and how to opt-out) here: https://docs.brew.sh/Analytics.html xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun Error: Failure while executing: git config --local --replace-all homebrew.analyticsmessage true ==> Tapping openresty/brew Cloning into \'/usr/local/Homebrew/Library/Taps/openresty/homebrew-brew\'... remote: Counting objects: 72, done. remote: Compressing objects: 100% (72/72), done. remote: Total 72 (delta 1), reused 44 (delta 0), pack-reused 0 Unpacking objects: 100% (72/72), done. Tapped 62 formulae (162 files, 131.7KB) ==> Installing openresty from openresty/brew Error: The following formula: openresty cannot be installed as a binary package and must be built from source. Install the Command Line Tools: xcode-select --install Sonofelice:bch-flowrouter baidu$ brew untap homebrew/nginx Error: No available tap homebrew/nginx. Sonofelice:bch-flowrouter baidu$ xcode-select --install xcode-select: note: install requested for command line developer tools
我遇到上面的错误,主要是因为缺少xcode-select
xcode-select --install
会弹出插件安装框,安装好之后再执行
brew install openresty/brew/openresty
进行安装即可。
还可能出现的错误二,安装过xcode command line,但是过期了,可以先删除/Library/Developer目录下的CommandLineTools文件夹,然后执行下面命令安装
xcode-select --install
安装完成后,启动openresty,命令行直接输入openresty即可。可能会看到如下错误:
nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
这是因为非root用户没有启动权限。使用sudo openresty启动即可。
在浏览器输入:http://127.0.0.1/
看到如下页面则表示openresty启动成功
二、helloworld
要本地跑一个helloworld,根据网上的教程,https://openresty.org/cn/getting-started.html
是需要执行下面的命令的:
nginx -p `pwd`/ -c conf/nginx.conf
如果找不到nginx这个命令,可以先去配置一下环境变量:
PATH=/usr/local/openresty/nginx/sbin:$PATH
export PATH
但是我自己的mac使用的是homebrew进行安装的,所以默认目录是
/usr/local/Cellar/openresty/1.13.6.1/nginx/sbin
记得去配置好自己的安装目录。
在自己的nginx.conf中,内容如下:
worker_processes 1; error_log logs/error.log; events { worker_connections 1024; } http { server { listen 8081; location / { default_type text/html; content_by_lua \' ngx.say("<p>hello, world</p>") \'; } } }
再使用
nginx -p `pwd`/ -c conf/nginx.conf
(停掉nginx进程可以在上述命令后面直接加 -s stop)
命令启动之后,然后curl
curl http://localhost:8081/
以上是关于openresty环境搭建问题记录的主要内容,如果未能解决你的问题,请参考以下文章