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

Tutorial diagram of installing centos7.3 on vmware virtual machine

VMware Preparation CentOS preparation, here is Ce...

The easiest way to debug stored procedures in Mysql

A colleague once told me to use a temporary table...

Vue Page Stack Manager Details

Table of contents 2. Tried methods 2.1 keep-alive...

Image scrolling effect made with CSS3

Achieve resultsImplementation Code html <base ...

Three common style selectors in html css

1: Tag selector The tag selector is used for all ...

How to shut down/restart/start nginx

closure service nginx stop systemctl stop nginx s...

The marquee element implements effects such as scrolling fonts and pictures

The marquee element can achieve simple font (image...

Detailed tutorial on configuring local yum source in CentOS8

The centos8 distribution is released through the ...

Understanding flex-grow, flex-shrink, flex-basis and nine-grid layout

1. flex-grow, flex-shrink, flex-basis properties ...

Teach you how to use docker-maven-plugin to automate deployment

1. Introduction to docker-maven-plugin In our con...

WeChat applet calculator example

WeChat applet calculator example, for your refere...

An article to help you thoroughly understand position calculation in js

Table of contents introduction scroll Element.scr...

HTML set as homepage and add to favorites_Powernode Java Academy

How to implement the "Set as homepage" ...