1. 添加源

wget https://openresty.org/package/centos/openresty.repo
sudo mv openresty.repo /etc/yum.repos.d/
sudo yum check-update

2. 安装

sudo yum install -y openresty

3. 使用

3.1 创建目录
mkdir -p /www/server/conf /www/server/logs
3.2 创建配置文件

/www/server/conf/目录下新建测试配置文件test.conf

vi /www/server/conf/test.conf

内容如下

worker_processes  1;
error_log logs/error.log;
events {
		worker_connections 1024;
}
http {
		server {
				listen 8080;
				location / {
						default_type text/html;
						content_by_lua_block {
								ngx.say("<p>hello, world</p>")
						}
				}
		}
}
3.3 添加环境变量

我选择直接添加在全部用户的里面vi /etc/profile

/usr/local/openresty 是openresty的默认安装目录。

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL前面添加PATH=/usr/local/openresty/nginx/sbin:$PATH,即

PATH=/usr/local/openresty/nginx/sbin:$PATH
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL

使其生效

source /etc/profile
3.4 启动服务
nginx -p `pwd`/ -c conf/test.conf 

注意的点:

-p `pwd`/  是指定目录路径,所以上面的前提是,你在/www/server/目录下面  也就是这句 nginx -c /www/server/conf/test.conf  等效
3.5 测试
curl http://localhost:8080/

结果返回

<p>hello, world</p>

成功。