Centos7 installation of Nginx integrated Lua sample code

Centos7 installation of Nginx integrated Lua sample code

Preface

The computer I use is a Mac, and the operating system is macOS Mojave. A virtual machine is installed on the computer.

The Centos7 operating system is installed on the virtual machine, and Nginx and Luau libraries are installed on it. The whole process is recorded after the system installation is completed.

It is recommended to take a snapshot before installation so that you can restore it if there is a problem.

Preparation

If the installed Linux can connect to the Internet and the Linux ports can be used normally externally, you can ignore the following two steps:

1. Set up automatic IP acquisition

(1) Enter the command on Linux

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

You can view the current network card information


Mine is ens33

(2) Modify information

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

Change the last line ONBOOT=no to ONBOOT=yes

(3) Restart network services

[root@localhost ~]# systemctl restart network 

2. Turn off the firewall

systemctl stop firewalld.service #Stop firewall
systemctl disable firewalld.service #Disable firewall startup

3. If you find that there is no wget command when preparing to install, you can first install it according to the line surface. If there is no wget command as prompted below, you can execute this step

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

Install

1. Install dependent environment

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

2. Install LuaJIT

I created the LuaJIT folder in the /usr/local path

[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. Install nginx

(1) Download ngx_devel_kit, lua-nginx-module, nginx

I created the nginx folder in the /usr/local path

[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 
#Note that the compressed package after downloading has no file name, but the version number can be used to distinguish which file it is [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) Compile 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) Installation

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

(4) Start nginx

Nginx may report an error when starting

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

The file libluajit-5.1.so.2 cannot be found

Solution

1. Find the two files libluajit-5.1.so.2 and libluajit-5.1.so.2.0.2 and copy them to the corresponding lib

64-bit is /usr/lib64

32-bit is /usr/lib

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

Discover


The file is installed by default in /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

In the nginx installation directory, modify the nginx.conf file

Add the following code under the Server code block

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

Start nginx

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

Access the virtual corresponding address http://xxx.xxx.xxx/hello in the browser

Display as follows


So far, we have succeeded

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • How to build Jenkins+Maven+Git continuous integration environment on CentOS7
  • Install centos7 virtual machine on win10
  • How to set a fixed IP address in CentOS7 virtual machine
  • How to use yum to configure lnmp environment in CentOS7.6 system
  • MySQL 8.0.13 installation and configuration tutorial under CentOS7.3
  • Rsync+crontab regular synchronization backup under centos7
  • Solve the problem of regular automatic file deletion by crontab+shell script under Centos7
  • Compile and install php7 on centos7 to connect to apache in php-fpm mode
  • Detailed tutorial on installing mysql 8.0.13 (rpm) on Centos7
  • Three methods to modify the hostname of Centos7

<<:  CentOS6.9+Mysql5.7.18 source code installation detailed tutorial

>>:  How to update the view synchronously after data changes in Vue

Recommend

JavaScript uses setTimeout to achieve countdown effect

In order to enhance the ability to write JavaScri...

canvas.toDataURL image/png error handling method recommendation

Problem background: There is a requirement to tak...

Organize the common knowledge points of CocosCreator

Table of contents 1. Scene loading 2. Find Node 1...

The visual design path of the website should conform to user habits

Cooper talked about the user's visual path, w...

Example of how to quickly build a LEMP environment with Docker

LEMP (Linux + Nginx + MySQL + PHP) is basically a...

How to define data examples in Vue

Preface In the development process, defining vari...

About front-end JavaScript ES6 details

Table of contents 1. Introduction 1.1 Babel Trans...

How does MySQL ensure data integrity?

The importance of data consistency and integrity ...

Detailed installation and uninstallation tutorial for MySQL 8.0.12

1. Installation steps for MySQL 8.0.12 version. 1...

MySQL scheduled backup solution (using Linux crontab)

Preface Although some love in this world has a pr...

mysql8.0.11 winx64 manual installation and configuration tutorial

First of all, let me talk to you about my daily l...

Analyze how uniapp dynamically obtains the interface domain name

background The interface domain name is not hard-...

JavaScript source code for Elimination

JavaScript to achieve the source code download ad...