Centos7安裝Nginx整合Lua的方法

準備工作

如果安裝的linux能夠聯網,并且外部也能正常使用linux的端口,那么可以忽略下面兩部

1.設置自動獲取ip

(1)在linux上輸入命令

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

可以查看當前網卡信息

Centos7安裝Nginx整合Lua的方法

我的是 ens33

(2)修改信息

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

將最后一行onboot=no 修改為 onboot=yes

(3)重啟網絡服務

[root@localhost?~]#?systemctl?restart?network

Centos7安裝Nginx整合Lua的方法

2.關閉防火墻

systemctl?stop?firewalld.service?#停止firewall systemctl?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

發現

Centos7安裝Nginx整合Lua的方法

文件默認是安裝在 /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")'; ??}

Centos7安裝Nginx整合Lua的方法

啟動nginx

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

在瀏覽器訪問 虛擬對應的地址 http://xxx.xxx.xxx/hello

顯示如下

Centos7安裝Nginx整合Lua的方法

? 版權聲明
THE END
喜歡就支持一下吧
點贊13 分享