本文主要讲解如何安装OpenResty。
# 1.OpenResty是什么
OpenResty是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库、第三方模块以及大多数的依赖项。
用于方便地搭建能够处理超高并发、扩展性极高的动态 Web 应用、Web 服务和动态网关。
# 2.安装
下面以openresty/1.15.8.3为例,进行说明如何安装。
# 2.1 安装系统依赖库
# yum install readline-devel pcre-devel openssl-devel
Copied!
1
# 2.2 安装yum源
# wget https://openresty.org/package/centos/openresty.repo # mv openresty.repo /etc/yum.repos.d/ # yum check-update
Copied!
1
2
3
2
3
# 2.3 安装openresty
# yum install -y openresty
Copied!
1
# 2.4 验证
# openresty -h nginx version: openresty/1.15.8.3 Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives] Options: -?,-h : this help -v : show version and exit -V : show version and configure options then exit -t : test configuration and exit -T : test configuration, dump it and exit -q : suppress non-error messages during configuration testing -s signal : send signal to a master process: stop, quit, reopen, reload -p prefix : set prefix path (default: /usr/local/openresty/nginx/) -c filename : set configuration file (default: conf/nginx.conf) -g directives : set global directives out of configuration file
Copied!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
# 3.部署
# 3.1 准备目录
# mkdir ~/work # cd ~/work # mkdir logs/ conf/
Copied!
1
2
3
2
3
# 3.2 编写nginx配置文件
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>") } } } }
Copied!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
注意:
- 如果端口被其他进程占用,改下端口即可。
- 建议配置文件增加一个配置user root;
# 3.2 追加环境变量
# vim ~/.bash_profile PATH=/usr/local/openresty/nginx/sbin:$PATH export PATH
Copied!
1
2
3
2
3
# 3.3 生效环境变量
# source ~/.bash_profile
Copied!
1
# 3.4 启动服务
# cd ~/work # nginx -p `pwd`/ -c conf/nginx.conf
Copied!
1
2
2
# 3.5 验证
访问网址http://localhost:8080/,出现hello, world就部署成功了。
欢迎关注我的公众号testerzhang,原创技术文章第一时间推送。
v1.4.16