跳转至

Openresty Install

centos7.9

添加仓库

wget https://openresty.org/package/centos/openresty.repo -O /etc/yum.repos.d/openresty.repo

列出所有 openresty 仓库里头的软件包:

yum --disablerepo="*" --enablerepo="openresty" list available

安装openresty

Bash
1
2
3
4
5
6
7
#查看可用版本
yum list available openresty --showduplicates
yum install -y openresty  #安装最新版本
yum install -y openresty-1.21.4.4  #安装指定版本,目前稳定版本

#降级特定版本
yum downgrade openresty-1.21.4.4

安装命令行工具 resty (可选)

Bash
yum install -y openresty-resty
yum install -y openresty-resty-1.21.4.4

查看安装包

Bash
1
2
3
4
5
root@pts/0 # rpm -qa|grep openresty
openresty-1.21.4.4-1.el7.x86_64
openresty-openssl111-1.1.1w-1.el7.x86_64
openresty-zlib-1.3.1-1.el7.x86_64
openresty-pcre-8.45-1.el7.x86_64

openresty安装在/usr/local/openresty

Bash
root@pts/0 # cd /usr/local/openresty
root@pts/0 # ll
总用量 24
drwxr-xr-x  2 root root    23 7月  21 15:22 bin
-rw-r--r--  1 root root 22924 10月 16 2024 COPYRIGHT
drwxr-xr-x  6 root root    56 7月  21 15:22 luajit
drwxr-xr-x  5 root root   105 7月  21 15:22 lualib
drwxr-xr-x 11 root root   151 7月  21 15:29 nginx
drwxr-xr-x  4 root root    28 7月  21 15:22 openssl111
drwxr-xr-x  3 root root    17 7月  21 15:22 pcre
drwxr-xr-x  3 root root    20 7月  21 15:22 site
drwxr-xr-x  3 root root    17 7月  21 15:11 zlib

简单配置下测试

Bash
root@pts/0 # cd nginx/conf
root@pts/0 # vim nginx.conf # 编辑配置文件
http {
    server {
        listen 80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
            # add conf
            default_type text/html;
            content_by_lua_block {
                ngx.say("<p>hello, world</p>")
            }
        }
    }
}
# 启动服务
root@pts/0 # systemctl start openresty
# 或者
root@pts/0 # service openresty start
# 也可以配置环境变量
root@pts/0 # vim /etc/profile
PATH=/usr/local/openresty/nginx/sbin:$PATH
export PATH
root@pts/0 # source /etc/profile
root@pts/0 # nginx -t
nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test is successful
root@pts/0 # nginx

服务启动后访问测试,也可以浏览器打开

Bash
root@pts/0 # curl http://localhost
<p>hello, world</p>

查看openresty默认加载了哪些模块

Bash
1
2
3
4
5
6
root@pts/0 # nginx -V
nginx version: openresty/1.21.4.4
built by gcc 11.2.1 20220127 (Red Hat 11.2.1-9) (GCC) 
built with OpenSSL 1.1.1w  11 Sep 2023
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt='-O2 -DNGX_LUA_ABORT_AT_PANIC -I/usr/local/openresty/zlib/include -I/usr/local/openresty/pcre/include -I/usr/local/openresty/openssl111/include' --add-module=../ngx_devel_kit-0.3.2 --add-module=../echo-nginx-module-0.63 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2 --add-module=../set-misc-nginx-module-0.33 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.09 --add-module=../srcache-nginx-module-0.33 --add-module=../ngx_lua-0.10.25 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.34 --add-module=../array-var-nginx-module-0.06 --add-module=../memc-nginx-module-0.19 --add-module=../redis2-nginx-module-0.15 --add-module=../redis-nginx-module-0.3.9 --add-module=../ngx_stream_lua-0.0.13 --with-ld-opt='-Wl,-rpath,/usr/local/openresty/luajit/lib -L/usr/local/openresty/zlib/lib -L/usr/local/openresty/pcre/lib -L/usr/local/openresty/openssl111/lib -Wl,-rpath,/usr/local/openresty/zlib/lib:/usr/local/openresty/pcre/lib:/usr/local/openresty/openssl111/lib' --with-cc='ccache gcc -fdiagnostics-color=always' --with-pcre-jit --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_v2_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_auth_request_module --with-http_secure_link_module --with-http_random_index_module --with-http_gzip_static_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-threads --with-compat --with-stream --with-http_ssl_module