1.インストール
例としてCentOSを取り上げます。
mkdir -p /opt
# download openresty
wget https://openresty.org/download/openresty-1.13.6.2.tar.gz
tar zxvf openresty-1.13.6.2.tar.gz
cd openresty-1.13.6.2
# configure
./configure --prefix=/opt/openresty -j4
make -j4 && make install
ソースコードパッケージはhttps://openresty.org/cn/download.htmlから入手でき ます 。-j4
4つのコアが使用されていることを示します。configure
また、そのステップでさまざまなパラメーターを指定して、./configure --help
より多くのオプションを表示するために使用することもでき ます。
他のシステム環境でのインストールについては、https://openresty.org/cn/installation.htmlを参照して ください 。
実際、OpenRestyはNginxに基づいて開発されているため、OpenRestyのインストールはNginxのインストールと似ています。
第二に、テスト
nginxでサポートされている3番目のモジュールを見つけます:https : //www.nginx.com/resources/wiki/modules/index.html
https://github.com/openresty/lua-nginx-module
Openresty初心者:https ://openresty.org/cn/getting-started.html
1. 1content_by_luaをテストする
/opt/openresty/nginx/conf/nginx.confを変更します
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
server {
listen 8080;
location / {
default_type text/html;
content_by_lua_block {
ngx.say("<p>hello, world</p>")
}
}
}
}
その中にcontent_by_lua
は、公式ドキュメントで検索できるOpenRestyによって提供される指示があります:https : //github.com/openresty/lua-nginx-module
/opt/openresty/nginx/sbin/nginx -s realod
curl http://localhost:8080/
2. 2content_by_lua_fileをテストします
/opt/openresty/nginx/conf/nginx.confを変更します
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
server {
listen 8080;
location / {
default_type text/html;
content_by_lua {
ngx.say("<p>hello, world</p>")
}
}
}
}
mkdir nginx/conf/lua
vim nginx/conf/lua/hello.lua
ngx.say("hello lua")
/opt/openresty/nginx/sbin/nginx -s reload
curl http://localhost/
3. 3lua_code_cacheをテストする
変更ごとにNginxを再起動する必要を回避するために、Nginx オプションのオプションをserver
構成できlua_code_cache
ます。
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
server {
listen 8080;
lua_code_cache off;
location / {
default_type text/html;
content_by_lua {
ngx.say("<p>hello, world</p>")
}
}
}
}
プロンプトは、lua_code_cache
クローズ後にパフォーマンスが影響を受けることを示しています。再度変更したnginx/conf/lua/hello.lua
コードは 、サーバーをリロードすることなく、保存後に有効になります。
lua_code_cache off;
エンジンNginxのパフォーマンスは、実稼働環境で有効になることに注意してください。
3.まとめ
OpenRestyでの開発は2つのステップに分かれています。最初のステップはNginx構成を変更することであり、2番目のステップはLuaを使用して独自のスクリプトを開発することです。