openresty环境搭建问题记录

第一次在mac安装遇到以下问题:html

截图:nginx

具体code以下:git

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-selectxcode

xcode-select --install

会弹出插件安装框,安装好以后再执行浏览器

brew install openresty/brew/openrestyapp

进行安装便可。curl

还可能出现的错误二,安装过xcode command line,可是过时了,能够先删除/Library/Developer目录下的CommandLineTools文件夹,而后执行下面命令安装ui

xcode-select --install

安装完成后,启动openresty,命令行直接输入openresty便可。可能会看到以下错误:lua

nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)url

这是由于非root用户没有启动权限。使用sudo openresty启动便可。

在浏览器输入:http://127.0.0.1/

看到以下页面则表示openresty启动成功

2、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/
相关文章
相关标签/搜索