日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

安装OpenResty开发环境

發(fā)布時間:2025/5/22 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 安装OpenResty开发环境 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

  OpenResty是一個基于?Nginx?與 Lua 的高性能 Web 平臺,其內部集成了大量精良的 Lua 庫、第三方模塊以及大多數的依賴項。用于方便地搭建能夠處理超高并發(fā)、擴展性極高的動態(tài) Web 應用、Web 服務和動態(tài)網關(摘自官網)。本文將會介紹如何在Centos7上,安裝Nginx+Lua的開發(fā)環(huán)境,并運行一個“Hello World”示例。

一、環(huán)境安裝

1.1 創(chuàng)建工作路徑

  我計劃將Openresty安裝到/usr/servers下,首先創(chuàng)建這個文件夾。

[root@localhost ~]# mkdir -p /usr/servers [root@localhost ~]# cd /usr/servers/ [root@localhost servers]#

1.2 安裝依賴庫

[root@localhost servers]# yum install readline-devel pcre-devel openssl-devel perl make gcc -y

1.3 下載Nginx及要安裝的模塊

  其中,ngx_cache_purge模塊用于清理nginx緩存,nginx_upstream_check_module用于ustream的健康檢查。

[root@localhost servers]# pwd /usr/servers [root@localhost servers]# wget http://openresty.org/download/ngx_openresty-1.7.7.2.tar.gz [root@localhost servers]# tar -xzvf ngx_openresty-1.7.7.2.tar.gz [root@localhost servers]# cd /usr/servers/ngx_openresty-1.7.7.2/bundle [root@localhost bundle]# pwd /usr/servers/ngx_openresty-1.7.7.2/bundle [root@localhost bundle]# wget https://github.com/FRiCKLE/ngx_cache_purge/archive/2.3.tar.gz [root@localhost bundle]# tar -xvf 2.3.tar.gz [root@localhost bundle]# cd /usr/servers/ngx_openresty-1.7.7.2/bundle [root@localhost bundle]# pwd /usr/servers/ngx_openresty-1.7.7.2/bundle [root@localhost bundle]# wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/v0.3.0.tar.gz [root@localhost bundle]# tar -xvf v0.3.0.tar.gz

1.4?安裝LuaJIT

[root@localhost bundle]# cd /usr/servers/ngx_openresty-1.7.7.2/bundle/LuaJIT-2.1-20150120/ [root@localhost LuaJIT-2.1-20150120]# pwd /usr/servers/ngx_openresty-1.7.7.2/bundle/LuaJIT-2.1-20150120 [root@localhost LuaJIT-2.1-20150120]# make clean && make && make install [root@localhost LuaJIT-2.1-20150120]# ln -sf luajit-2.1.0-alpha /usr/local/bin/luajit [root@localhost LuaJIT-2.1-20150120]# lua -v Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio [root@localhost LuaJIT-2.1-20150120]# luajit -v LuaJIT 2.1.0-alpha -- Copyright (C) 2005-2015 Mike Pall. http://luajit.org/

1.5 安裝ngx_openresty

[root@localhost LuaJIT-2.1-20150120]# cd /usr/servers/ngx_openresty-1.7.7.2 [root@localhost ngx_openresty-1.7.7.2]# pwd /usr/servers/ngx_openresty-1.7.7.2 [root@localhost ngx_openresty-1.7.7.2]# ./configure --prefix=/usr/servers --with-http_realip_module --with-pcre --with-luajit --add-module=./bundle/ngx_cache_purge-2.3/ --add-module=./bundle/nginx_upstream_check_module-0.3.0/ -j2 [root@localhost ngx_openresty-1.7.7.2]# make && make install

  至此,基本的環(huán)境已經安裝完成了,nginx可執(zhí)行文件為:/usr/servers/nginx/sbin/nginx,可以通過/usr/servers/nginx/sbin/nginx -V 命令來查看nginx的版本及安裝的模塊。

二、環(huán)境配置及示例

?2.1 配置nginx.conf

  nginx.conf是Nginx的主配置文件,所有的配置都是從這里開始的。我的計劃是將lua腳本、依賴庫配置、與lua相關的server、location等配置都放到外部的目錄中,這樣不用每次都動到nginx.conf。修改/usr/servers/nginx/conf/nginx.conf,如下:

[root@localhost ~]#?cat?/usr/servers/nginx/conf/nginx.conf
worker_processes
1;error_log logs/error.log; events {worker_connections 1024; }http {include mime.types; default_type text/html; #lua模塊路徑lua_package_path "/usr/example/lualib/?.lua;;"; #lua 模塊 lua_package_cpath "/usr/example/lualib/?.so;;"; #c模塊 include /usr/example/example.conf; }

2.2 配置example.conf

[root@localhost ~]# mkdir /usr/example [root@localhost ~]# vim /usr/example/example.conf [root@localhost ~]# cat /usr/example/example.conf server {listen 80;server_name _;location /lua {default_type 'text/html';lua_code_cache off;content_by_lua_file /usr/example/lua/test.lua;} }

2.3 示例——test.lua

[root@localhost ~]# mkdir /usr/example/lua [root@localhost ~]# vim /usr/example/lua/test.lua [root@localhost ~]# cat /usr/example/lua/test.lua ngx.say("hello world");

2.4 驗證

  首先啟動nginx,你會發(fā)現(xiàn)nginx給了一個警告,這句警告是因為在/usr/example/example.conf的第7行上,我們關閉了lua_code_cache。這個配置默認是打開的,即Nginx在啟動的時候會將lua腳本都cache起來,這樣系統(tǒng)在調用這些腳本時就會很快。而關閉這個配置的話,nginx每次調用都會重新load一遍,會對性能有一定的影響。因為我們是在開發(fā)環(huán)境,我們不希望更改腳本之后就重啟nginx,所以就把這個配置給關閉了。

[root@localhost ~]# /usr/servers/nginx/sbin/nginx nginx: [alert] lua_code_cache is off; this will hurt performance in /usr/example/example.conf:7

接下來在瀏覽器中訪問對應的路徑,你會得到如下的結果。(提示:若沒有出現(xiàn),可以檢查一下系統(tǒng)防火墻)

?

備注:

centos下還可以通過yum的方式安裝openresty,但在國內的網絡環(huán)境下,這種方式時靈時不靈(國外的主機上就沒有問題),我懷疑是國內網絡的問題。有興趣的同學可以嘗試下。具體命令如下:

yum install yum-utils yum-config-manager --add-repo https://openresty.org/yum/centos/OpenResty.repo yum install openresty

?

轉載于:https://www.cnblogs.com/zhenyuyaodidiao/p/7061706.html

總結

以上是生活随笔為你收集整理的安装OpenResty开发环境的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。