第一次在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/
