openresty安装与网站发布

文章目录

OpenResty® 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库、第三方模块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性极高的动态 Web 应用、Web 服务和动态网关。

OpenResty® 通过汇聚各种设计精良的 Nginx 模块(主要由 OpenResty 团队自主开发),从而将 Nginx 有效地变成一个强大的通用 Web 应用平台。这样,Web 开发人员和系统工程师可以使用 Lua 脚本语言调动 Nginx 支持的各种 C 以及 Lua 模块,快速构造出足以胜任 10K 乃至 1000K 以上单机并发连接的高性能 Web 应用系统。

OpenResty® 的目标是让你的Web服务直接跑在 Nginx 服务内部,充分利用 Nginx 的非阻塞 I/O 模型,不仅仅对 HTTP 客户端请求,甚至于对远程后端诸如 MySQL、PostgreSQL、Memcached 以及 Redis 等都进行一致的高性能响应。

安装依赖

shell 复制代码
yum install libtermcap-devel ncurses-devel libevent-devel readline-devel pcre-devel gcc openssl openssl-devel per perl wget

下载安装包

shell 复制代码
wget https://openresty.org/download/openresty-1.21.4.2.tar.gz
wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz

解压安装包

shell 复制代码
tar -zxvf openresty-1.21.4.2.tar.gz -C /opt/local/
tar -zxvf ngx_cache_purge-2.3.tar.gz -C /opt/local/
chown -R root:root /opt/local/ngx_cache_purge-2.3

安装

shell 复制代码
cd openresty-1.21.4.2

#安装
./configure --prefix=/usr/local/openresty \
--with-luajit --without-http_redis2_module \
--with-http_stub_status_module \
--with-http_v2_module \
--with-http_gzip_static_module \
--with-http_sub_module \
--add-module=/opt/local/ngx_cache_purge-2.3

说明:

--prefix=/usr/local/openresty: 安装路径
--with-luajit: 安装luajit库,luajit是lua的一个高效版,LuaJIT的运行速度比标准Lua快数十倍。
--without-http_redis2_module: 现在使用的是Redis都是3.x以上版本,这里不推荐使用redis2,表示不安装redis2支持的lua库。
--with-http_stub_status_module: http对应的状态库
--with-http_v2_module: 对http2的支持
--with-http_gzip_static_module: gzip服务端压缩支持
--with-http_sub_module: 过滤器,可以通过将一个指定的字符串替换为另一个字符串来修改响应。
--add-module=/opt/local/ngx_cache_purpe-2.3/: nginx代理缓存清理工具
shell 复制代码
# 编译并安装,这里根据上面提示信息,使用gmake
gmake && gmake install

安装完成,显示如下:

上面可以看出,在/usr/local/openresty/nginx下是安装好的nginx,后面的静态网站发布将在该目录下发布。

启动nginx

shell 复制代码
cd /usr/local/openresty/nginx/sbin/
./nginx

在浏览器访问:

http://192.168.80.250

配置环境变量

编辑文件/etc/profile

#nginx
export PATH=/usr/local/openresty/nginx/sbin:$PATH

配置开机启动

创建文件:/usr/lib/systemd/system/nginx.service,在该文件中编写启动nginx脚本:

shell 复制代码
[Service]
Type=forking
PIDFile=/usr/local/openresty/nginx/logs/nginx.pid
ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t
ExecStart=/usr/local/openresty/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target

systemctl daemon-reload:重新加载某个服务的配置文件
systemctl enable nginx.service:开机启动
systemctl start nginx.service: 启动nginx

发布静态网站

将静态网站放到服务器上,这里放的目录为/opt/local/web/frant

配置nginx

worker_processes  1;
events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    #门户网站,如果服务器有绑定域名,可以将localhost替换为域名
    server {
        listen       8881;
        server_name  localhost;
        
        location / {
           root /opt/local/web/frant;
        }
    }

}

重启nginx

systemctl stop nginx.service
systemctl start nginx.service

登录商城地址,如下:

相关推荐
爱编码的钓鱼佬6 天前
浅谈openresty
运维·nginx·openresty
shall_zhao6 天前
安装OpenResty(Linux-Docker)
linux·docker·openresty
shall_zhao9 天前
黑马点评18——多级缓存-OpenResty
redis·缓存·lua·openresty
代码是谁9 天前
centos8构建nginx1.27.1+BoringSSL+http3+lua+openresty
nginx·lua·http3·openresty
刘大帅ps1 个月前
高性能 Web 服务器:让网页瞬间绽放的魔法引擎(下)
linux·运维·服务器·网络·nginx·负载均衡·openresty
ciqingloveless1 个月前
openresty整合modsecurity实现简单的防止DDOS攻击
ddos·openresty
Roc-xb2 个月前
Docker安装 OpenResty详细教程
docker·容器·openresty
秃了也弱了。2 个月前
OpenResty使用Lua笔记
lua·openresty
路多辛2 个月前
OpenResty程序如何连接开启了TLS的Redis?
数据库·redis·openresty
serve the people2 个月前
Openresty+lua 定时函数 ngx.timer.every
开发语言·lua·openresty