当前位置:网站首页>Openresty usage document
Openresty usage document
2022-06-27 05:53:00 【No king in hand】
1. Download and install
1.1 download
wget https://openresty.org/package/centos/openresty.repo sudo mv openresty.repo /etc/yum.repos.d/ sudo yum check-update
1.2 install
sudo yum install -y openresty sudo yum install -y openresty-resty
2. start-up
2.1 Create directory
mkdir -p /opt/data/openresty/www/{logs,conf}2.2 create profile
[[email protected] opt] vi /opt/data/openresty/www/conf/nginx.conf worker_processes 1; error_log logs/error.log; events { worker_connections 1024; } http { lua_code_cache off; charset 'utf-8'; add_header Access-Control-Allow-Origin *; server { listen 9000; location / { default_type text/html; content_by_lua 'ngx.say("<p>Hello, World!</p>")'; } } }
2.3 start-up
[[email protected] opt]# /usr/local/openresty/nginx/sbin/nginx -p /opt/data/openresty/www/ -c /opt/data/openresty/www/conf/nginx.conf nginx: [alert] lua_code_cache is off; this will hurt performance in /opt/data/openresty/www/conf/nginx.conf:7 # =============================================================================== perhaps /usr/local/openresty/nginx/sbin/nginx -p `pwd`/ -c conf/nginx.conf # ==================================================================================
3. verification
3.1 Check the configuration
[[email protected] lua]# openresty -V nginx version: openresty/1.21.4.1 built by gcc 10.2.1 20200804 (Red Hat 10.2.1-2) (GCC) built with OpenSSL 1.1.1n 15 Mar 2022 TLS SNI support enabled configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt='-O2 -DNGX_LUA_ABORT_AT_PANIC -I/usr/local/openresty/zlib/include -I/usr/local/openresty/pcre/include -I/usr/local/openresty/openssl111/include' --add-module=../ngx_devel_kit-0.3.1 --add-module=../echo-nginx-module-0.62 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2 --add-module=../set-misc-nginx-module-0.33 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.09 --add-module=../srcache-nginx-module-0.32 --add-module=../ngx_lua-0.10.21 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.33 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.19 --add-module=../redis2-nginx-module-0.15 --add-module=../redis-nginx-module-0.3.9 --add-module=../ngx_stream_lua-0.0.11 --with-ld-opt='-Wl,-rpath,/usr/local/openresty/luajit/lib -L/usr/local/openresty/zlib/lib -L/usr/local/openresty/pcre/lib -L/usr/local/openresty/openssl111/lib -Wl,-rpath,/usr/local/openresty/zlib/lib:/usr/local/openresty/pcre/lib:/usr/local/openresty/openssl111/lib' --with-cc='ccache gcc -fdiagnostics-color=always' --with-pcre-jit --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_v2_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_auth_request_module --with-http_secure_link_module --with-http_random_index_module --with-http_gzip_static_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-threads --with-compat --with-stream --with-http_ssl_module
3.2 visit 80 port

3.3 visit 9000 port

thus ,Openresty Successfully built .
4. Optimize the structure of the directory
We put lua Code placed in nginx Configuration will be accompanied by lua Because of the increase of the code, the configuration file is too long to maintain , So we should take lua Move the code to an external file to store
4.1 Separate storage lua file
mkdir -p /opt/data/openresty/lua/
vi /opt/data/openresty/lua/test.lua
local date=os.date('%Y-%m-%d %H:%M:%S');
local html = [[
<html>
<head></head>
<body>
<a href="http://www.runoob.com/">hello world by lua! Chinese test </a>
</body>
</html>
]];
ngx.say(html , date );
tab1 = { key1 = "val1", key2 = "val2", key3 ="val3" };
for k, v in pairs(tab1) do
ngx.say(k .. " - " .. v);
end4.2 Modify the configuration file
vi /opt/data/openresty/www/conf/nginx.confworker_processes 1;error_log logs/error.log;events {worker_connections 1024;}http {lua_code_cache off;charset 'utf-8';add_header Access-Control-Allow-Origin *;server {listen 9000;location / {default_type text/html;content_by_lua_file /opt/data/openresty/lua/test.lua;}}}
4.3 Reload configuration
[[email protected] opt]# /usr/local/openresty/nginx/sbin/nginx -p /opt/data/openresty/www/ -c /opt/data/openresty/www/conf/nginx.conf -s reload nginx: [alert] lua_code_cache is off; this will hurt performance in /opt/data/openresty/www/conf/nginx.conf:7
4.4 visit 9000 port

边栏推荐
- Experience oceanbase database under win10
- Formation and release of function stack frame
- 函数栈帧的形成与释放
- MATLAB快速将影像的二维坐标转换为经纬度坐标
- QListWidget中的内容不显示
- 【FPGA】基于bt1120时序设计实现棋盘格横纵向灰阶图数据输出
- Neo4j database export
- Flink生产问题(1.10)
- Assembly language - Wang Shuang Chapter 13 int instruction - Notes
- DAST black box vulnerability scanner part 6: operation (final)
猜你喜欢

Discussion on streaming media protocol (MPEG2-TS, RTSP, RTP, RTCP, SDP, RTMP, HLS, HDS, HSS, mpeg-dash)

导航【机器学习】

Asp.Net Core6 WebSocket 简单案例

Two position relay xjls-8g/220

程序猿学习抖音短视频制作

Wechat applet websocket use case

多线程基础部分Part3

LeetCode-515. Find the maximum value in each tree row

微信小程序WebSocket使用案例

RTP sending PS stream tool (open source)
随机推荐
Get system volume across platforms in unity
Unity中跨平臺獲取系統音量
Interview: what are the positioning methods in selenium? Which one do you use most?
QListWidgetItem上附加widget
Avoid asteroids
Contents in qlistwidget are not displayed
Database - index
Experience oceanbase database under win10
Comprehensive application of OpenCV in contour detection and threshold processing
RTP sending PS stream tool (open source)
[cocos creator 3.5.1] addition of coordinates
QT using Valgrind to analyze memory leaks
Opencv implements object tracking
LeetCode-515. Find the maximum value in each tree row
程序猿学习抖音短视频制作
jq怎么获取元素的id名
Remapping (STM32)
Go log -uber open source library zap use
汇编语言-王爽 第9章 转移指令的原理-笔记
Acwing's 57th weekly match -- BC question is very good