千家信息网

Centos7 安装Nginx整合Lua的示例代码

发表于:2025-12-03 作者:千家信息网编辑
千家信息网最后更新 2025年12月03日,前言本人的使用的电脑是Mac,操作系统是macOS Mojave。电脑上装有虚拟机。虚拟机上安装Centos7操作系统,在其之上安装Nginx及Luau类库,整个过程是在系统安装完成之后开始记录。建议
千家信息网最后更新 2025年12月03日Centos7 安装Nginx整合Lua的示例代码

前言

本人的使用的电脑是Mac,操作系统是macOS Mojave。电脑上装有虚拟机。

虚拟机上安装Centos7操作系统,在其之上安装Nginx及Luau类库,整个过程是在系统安装完成之后开始记录。

建议安装前先拍快照,出现问题可以恢复

准备工作

如果安装的Linux能够联网,并且外部也能正常使用Linux的端口,那么可以忽略下面两部

1.设置自动获取ip

(1)在Linux上输入命令

[root@localhost ~]ip addr  #查看ip[root@localhost ~]nmcli connection show

可以查看当前网卡信息


我的是 ens33

(2)修改信息

[root@localhost ~]vi /etc/sysconfig/network-scripts/ifcfg-ens33

将最后一行ONBOOT=no 修改为 ONBOOT=yes

(3)重启网络服务

[root@localhost ~]# systemctl restart network

2.关闭防火墙

systemctl stop firewalld.service #停止firewallsystemctl disable firewalld.service #禁止firewall开机启动

3.准备安装是发现没有wget命令,可以先按照线面安装如果下面提示没有wget命令时,可以执行这一步

[root@localhost ~]#yum -y install wget

安装

1.安装依赖环境

[root@localhost ~]#yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

2.安装LuaJIT

我是在/usr/local路径下创建了 LuaJIT 文件夹

[root@localhost LuaJIT]#wget http://luajit.org/download/LuaJIT-2.0.2.tar.gz[root@localhost LuaJIT]#tar -xvf LuaJIT-2.0.2.tar.gz[root@localhost LuaJIT]#cd LuaJIT-2.0.2[root@localhost LuaJIT-2.0.2]#make install

3.安装nginx

(1)下载ngx_devel_kit、lua-nginx-module、nginx

我是在/usr/local路径下创建了 nginx 文件夹

[root@localhost nginx]#wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz[root@localhost nginx]#wget https://github.com/openresty/lua-nginx-module/archive/v0.10.9rc7.tar.gz[root@localhost nginx]#wget http://nginx.org/download/nginx-1.12.1.tar.gz #注意下载后的压缩包没有文件名称,但是根据版本号能区分是哪个文件[root@localhost nginx]#tar -xvf v0.3.0.tar.gz[root@localhost nginx]#tar -xvf v0.10.9rc7.tar.gz[root@localhost nginx]#tar -xvf nginx-1.12.1.tar.gz

(2)编译Nginx

[root@localhost nginx]# cd nginx-1.12.1[root@localhost nginx-1.12.1]#./configure --prefix=/usr/local/nginx --add-module=../ngx_devel_kit-0.3.0 --add-module=../lua-nginx-module-0.10.9rc7

(3)安装

[root@localhost nginx-1.12.1]#make[root@localhost nginx-1.12.1]#make install

(4)启动nginx

启动时会nginx可能会报错

./nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: N

找不到libluajit-5.1.so.2这个文件

解决办法

1.找到 libluajit-5.1.so.2,libluajit-5.1.so.2.0.2这两个文件复制到 对应的lib下

64位是 /usr/lib64

32位是 /usr/lib

[root@localhost nginx-1.12.1]#find / -name libluajit-5.1.so.2

发现


文件默认是安装在 /usr/local/lib/libluajit-5.1.so.2下

[root@localhost nginx-1.12.1]#cp /usr/local/lib/libluajit-5.1.so.2 /usr/lib64/[root@localhost nginx-1.12.1]#cp /usr/local/lib/libluajit-5.1.so.2.0.2 /usr/lib64

在nginx安装目录下,修改nginx.conf文件

在Server代码块下添加如下代码

location /hello{    default_type 'text/plain';    content_by_lua 'ngx.say("hello,lua")';  }

启动nginx

[root@localhost nginx-1.12.1]#./configure

在浏览器访问 虚拟对应的地址 http://xxx.xxx.xxx/hello

显示如下


到此就成功了

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

文件 命令 是在 系统 代码 操作系统 信息 文件夹 电脑 路径 准备 成功 一行 上装 两个 内容 前言 办法 名称 地址 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 数据库同时操作 支点网络技术有限公司 相近的手机号都在防骗数据库 网络安全征文名字 徐汇区数据库安防系统厂家等级 csgo里躲猫猫服务器 怀旧服服务器埃提耶什阵营比例 服务器主机硬盘多大 国家网络安全宣传周新沂在行动 动物大战僵尸2服务器 计算机网络安全从本质上 山东省网络安全局招聘 南京疆界互联网科技有限公司 如何制作一个数据库网站 北海网络安全保卫支队万圣 开机有服务器管理工具 高频率读用什么类型数据库 河南猩时代互联网科技公司 win7怎么进入服务器管理器 学校数据库怎么导出英文参考文献 网络安全部门一般要做什么 蚌埠电商系统软件开发 查询所有数据库的代码 网络技术三级题库 西安华夏网络技术有限公司 嘀嗒软件开发票 360网络安全职业技能 网络安全审查办公室百度百科 网络安全保障能力调查问卷 汤森数据库
0