当前位置:网站首页>openresty使用文档
openresty使用文档
2022-06-27 05:41:00 【手里没有王】
1.下载安装
1.1下载
wget https://openresty.org/package/centos/openresty.repo sudo mv openresty.repo /etc/yum.repos.d/ sudo yum check-update
1.2安装
sudo yum install -y openresty sudo yum install -y openresty-resty
2.启动
2.1创建目录
mkdir -p /opt/data/openresty/www/{logs,conf}2.2创建配置文件
[[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启动
[[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 # =============================================================================== 或者 /usr/local/openresty/nginx/sbin/nginx -p `pwd`/ -c conf/nginx.conf # ==================================================================================
3.验证
3.1查看配置
[[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访问80端口

3.3访问9000端口

至此,Openresty 已成功搭建。
4.目录结构优化
我们把lua代码放在nginx配置中会随着lua的代码的增加导致配置文件太长不好维护,因此我们应该把lua代码移到外部文件中存储
4.1单独存放lua文件
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!中文测试</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修改配置文件
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重新加载配置
[[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访问9000端口

边栏推荐
- Some articles about component packaging and my experience
- What is BFC? What's the usage?
- 重映像(STM32)
- 论文解读(LG2AR)《Learning Graph Augmentations to Learn Graph Representations》
- 693. 交替位二进制数
- OpenCV的轮廓检测和阈值处理综合运用
- 高翔slam14讲-笔记1
- Ad22 Gerber files Click to open the Gerber step interface. Official solutions to problems
- 树莓派4B上运行opcua协议DEMO接入kubeedge
- 310. 最小高度树
猜你喜欢

Reading graph augmentations to learn graph representations (lg2ar)

Two position relay hjws-9440

RTP 发送PS流工具(已经开源)

Open the door small example to learn ten use case diagrams

思维的技术:如何破解工作生活中的两难冲突?

Web3 has not been implemented yet, web5 suddenly appears!
![Navigation [machine learning]](/img/79/8311a409113331e72f650a83351b46.png)
Navigation [machine learning]

双位置继电器JDP-1440/DC110V

neo4j图数据库基本概念

Junda technology - centralized monitoring scheme for multi brand precision air conditioners
随机推荐
开门小例子学习十种用例图
C language implementation timer
躲避小行星游戏
How win 10 opens the environment variables window
Web3 has not been implemented yet, web5 suddenly appears!
LeetCode-515. 在每个树行中找最大值
Codeforces Round #802 (Div. 2)
Spark 之 built-in functions
STM32关闭PWM输出时,让IO输出固定高或低电平的方法。
DAST 黑盒漏洞扫描器 第六篇:运营篇(终)
Avoid asteroids
Netease cloud music params and encseckey parameter generation code
[FPGA] realize the data output of checkerboard horizontal and vertical gray scale diagram based on bt1120 timing design
网易云音乐params和encSecKey参数生成代码
C语言实现定时器
思维的技术:如何破解工作生活中的两难冲突?
函数式 连续式
Flink生产问题(1.10)
Junda technology - centralized monitoring scheme for multi brand precision air conditioners
论文解读(LG2AR)《Learning Graph Augmentations to Learn Graph Representations》