centos 7 OpenResty®(lua-nginx-module)搭建可扩展的Web平台
OpenResty®-英文官网地址:http://openresty.org/en/
OpenResty®-中文官网地址: http://openresty.org/cn/
OpenResty®> https://openresty.org/en/linux-packages.html
centos yun-command
sudo yum install yum-utils
sudo yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo
sudo yum install openresty-resty //安装resty命令行实用程序
下载> https://openresty.org/en/download.html
源代码> https://openresty.org/download/openresty-1.15.8.2.tar.gz
# [root@localhost openresty-1.15.8.2]# yum install -y gcc gcc-c++ iptables-services perl pcre-devel openssl-devel zlib wget lrzsz ntpdate
# [root@localhost src]# wget https://openresty.org/download/openresty-1.15.8.2.tar.gz -P /usr/local/src
# [root@localhost src]# tar -zxvf openresty-1.15.8.2.tar.gz
# [root@localhost src]# cd openresty-1.15.8.2
# [root@localhost openresty-1.15.8.2]# ls
# bundle configure COPYRIGHT patches README.markdown README-windows.txt util
# [root@localhost openresty-1.15.8.2]# ./configure
# Configuration summary
# + using system PCRE library
# + using system OpenSSL library
# + using system zlib library
#
# nginx path prefix: "/usr/local/openresty/nginx"
# nginx binary file: "/usr/local/openresty/nginx/sbin/nginx"
# nginx modules path: "/usr/local/openresty/nginx/modules"
# nginx configuration prefix: "/usr/local/openresty/nginx/conf"
# nginx configuration file: "/usr/local/openresty/nginx/conf/nginx.conf"
# nginx pid file: "/usr/local/openresty/nginx/logs/nginx.pid"
# nginx error log file: "/usr/local/openresty/nginx/logs/error.log"
# nginx http access log file: "/usr/local/openresty/nginx/logs/access.log"
# nginx http client request body temporary files: "client_body_temp"
# nginx http proxy temporary files: "proxy_temp"
# nginx http fastcgi temporary files: "fastcgi_temp"
# nginx http uwsgi temporary files: "uwsgi_temp"
# nginx http scgi temporary files: "scgi_temp"
#
# cd ../..
# Type the following commands to build and install:
# gmake
# gmake install
# [root@localhost openresty-1.15.8.2]# gmake && gmake install
# make[]: Leaving directory `/usr/local/src/openresty-1.15.8.2/build/nginx-1.15.'
# make[]: Leaving directory `/usr/local/src/openresty-1.15.8.2/build/nginx-1.15.'
# mkdir -p /usr/local/openresty/site/lualib /usr/local/openresty/site/pod /usr/local/openresty/site/manifest
# ln -sf /usr/local/openresty/nginx/sbin/nginx /usr/local/openresty/bin/openresty
# [root@localhost openresty-1.15.8.2]# cd /usr/local/openresty/
# [root@localhost openresty]# ls
# bin COPYRIGHT luajit lualib nginx pod resty.index site
# [root@localhost openresty]# ll bin |grep openresty
# lrwxrwxrwx root root Oct : openresty -> /usr/local/openresty/nginx/sbin/nginx
[root@localhost sbin]# ln -sf `pwd`/nginx /usr/local/sbin/nginx
# !bin/bash
# echo '#!/bin/bash
# chkconfig:
# nginx=/usr/local/openresty/nginx/sbin/nginx
# case "$1" in
# start)
# echo "Starting nginx daemon..."
# $nginx && echo "Success"
# ;;
# stop)
# echo "Stopping nginx daemon..."
# $nginx -s stop && echo "Success"
# ;;
# reload)
# echo "Reloading nginx daemon..."
# $nginx -s reload && echo "Success"
# ;;
# restart)
# echo "Restarting nginx daemon..."
# $nginx -s quit
# $nginx && echo "Success"
# ;;
# reopen)
# echo "Reopening nginx daemon..."
# $nginx -s reopen && echo "Success"
# ;;
# *)
# echo "Please useing nginx {start|stop|retart|reload|reopen}"
# exit2
# ;;
# esac' > /etc/init.d/nginx
# chmod /etc/init.d/nginx
# chkconfig --add nginx
# chkconfig --level nginx on //0-6运行级别可用
# [root@localhost sbin]# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport -j ACCEPT
# [root@localhost sbin]# service iptables save
# iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
# [root@localhost sbin]# systemctl restart iptables
# [root@localhost sbin]# iptables -L -n
# Chain INPUT (policy ACCEPT)
# target prot opt source destination
# ACCEPT tcp -- 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
#
# Chain FORWARD (policy ACCEPT)
# target prot opt source destination
#
# Chain OUTPUT (policy ACCEPT)
# target prot opt source destination
# [root@localhost sbin]# nginx
# [root@localhost sbin]# nginx -s reload # 关于OpenResty目录结构的具体说明如下
# ●bin:存放二进制可执行文件.
# ●luajit:存放LuaJIT(Lua代码解释器)相关的文件.
# ●lualib:存放Lua库文件.
# ●nginx:OpenResty整合的Nginx存放在这个目录.
# ●pod:存放用于bin/restydoc程序读取的pod文档.
# ●resty.in ndex:存放pod文档的索引.
# ●site:OPM(OpenResty Package Manager)包的存放目录. # OpenResty主要应用在一些对性能要求非常高的场合,例如WAF(Web Application Firewall,Web应用防火墙)、
# CDN(Content Delivery Network,内容分发网络)调度、广告系统、消息推送系统、RESTful API(一种服务器接口技术)等.
# 一些知名的互联网公司如 CloudFlare 、奇虎360、新浪、京东等都在使用OpenResty相关的技术.
# OpenResty平台离不开 Nginx 和 Lua 语言,读者可通过GitHub开源平台中的openresty-best practices. # [root@localhost bin]# ./resty -e 'print("hello,my name is kings-dev.")'
# hello,my name is kings-dev.
# [root@localhost bin]# ./restydoc -s proxy_pass
# ngx_http_proxy_module() nginx ngx_http_proxy_module()
#
#
#
# proxy_pass
# syntax: proxy_pass "URL"
#
# context: location
#
# context: if in location
#
# context: limit_except
#
# Sets the protocol and address of a proxied server and an optional URI
# to which a location should be mapped. As a protocol, “"http"” or
# “"https"” can be specified. The address can be specified as a domain
# name or IP address, and an optional port:
#
# proxy_pass http://localhost:8000/uri/;
#
# or as a UNIX-domain socket path specified after the word “"unix"” and
# enclosed in colons:
#
# proxy_pass http://unix:/tmp/backend.socket:/uri/;
#
# If a domain name resolves to several addresses, all of them will be
# used in a round-robin fashion. In addition, an address can be
# specified as a server group.
#
# Parameter value can contain variables. In this case, if an address is
# specified as a domain name, the name is searched among the described
# server groups, and, if not found, is determined using a
# ngx_http_core_module.
#
# A request URI is passed to the server as follows:
#
# · If the "proxy_pass" directive is specified with a URI, then when a
# request is passed to the server, the part of a normalized request
# URI matching the location is replaced by a URI specified in the
# directive:
#
# location /name/ {
# proxy_pass http://127.0.0.1/remote/;
# }
#
# · If "proxy_pass" is specified without a URI, the request URI is
# passed to the server in the same form as sent by a client when the
# original request is processed, or the full normalized request URI
# is passed when processing the changed URI:
#
# location /some/path/ {
# proxy_pass http://127.0.0.1;
# }
#
# NOTE
# ngx_http_proxy_module() nginx ngx_http_proxy_module()
#
#
#
# proxy_pass
# syntax: proxy_pass "URL"
#
# context: location
#
# context: if in location
#
# context: limit_except
#
# Sets the protocol and address of a proxied server and an optional URI
# to which a location should be mapped. As a protocol, “"http"” or
# “"https"” can be specified. The address can be specified as a domain
# name or IP address, and an optional port:
#
# proxy_pass http://localhost:8000/uri/;
#
# or as a UNIX-domain socket path specified after the word “"unix"” and
# enclosed in colons:
#
# proxy_pass http://unix:/tmp/backend.socket:/uri/;
#
# If a domain name resolves to several addresses, all of them will be
# used in a round-robin fashion. In addition, an address can be
# specified as a server group.
#
# Parameter value can contain variables. In this case, if an address is
# specified as a domain name, the name is searched among the described
# server groups, and, if not found, is determined using a
# ngx_http_core_module.
#
# A request URI is passed to the server as follows:
#
# · If the "proxy_pass" directive is specified with a URI, then when a
# request is passed to the server, the part of a normalized request
# URI matching the location is replaced by a URI specified in the
# directive:
#
# location /name/ {
# proxy_pass http://127.0.0.1/remote/;
# }
#
# · If "proxy_pass" is specified without a URI, the request URI is
# passed to the server in the same form as sent by a client when the
# original request is processed, or the full normalized request URI
# is passed when processing the changed URI:
#
# location /some/path/ {
# proxy_pass http://127.0.0.1;
# }
#
# NOTE
#
# Before version 1.1., if "proxy_pass" is specified without a URI,
# the original request URI might be passed instead of the changed URI
# in some cases.
#
# In some cases, the part of a request URI to be replaced cannot be
# determined:
#
# · When location is specified using a regular expression, and also
# inside named locations.
#
# In these cases, "proxy_pass" should be specified without a URI.
#
# · When the URI is changed inside a proxied location using the
# ngx_http_rewrite_module directive, and this same configuration will
# be used to process a request ("break"):
#
# location /name/ {
# rewrite /name/([^/]+) /users?name=$ break;
# proxy_pass http://127.0.0.1;
# }
#
# In this case, the URI specified in the directive is ignored and the
# full changed request URI is passed to the server.
#
# · When variables are used in "proxy_pass":
#
# location /name/ {
# proxy_pass http://127.0.0.1$request_uri;
# }
#
# In this case, if URI is specified in the directive, it is passed to
# the server as is, replacing the original request URI.
#
# WebSocket proxying requires special configuration and is supported
# since version 1.3..
#
#
#
# OpenResty -- ngx_http_proxy_module() # [root@localhost bin]# cd
# [root@localhost ~]# mkdir openresty_work
# [root@localhost ~]# cd openresty_work/
# [root@localhost openresty_work]# mkdir logs conf
# [root@localhost openresty_work]# ls -lF
# total
# drwxr-xr-x root root Oct : conf/
# drwxr-xr-x root root Oct : logs/ # [root@localhost openresty_work]# vi openresty_nginx_conf.sh #!/bin/bash
echo "worker_processes 1;
error_log logs/error.log;
events {
worker_connections ;
}
http {
server {
listen ;
location /{
default_type text/html;
content_by_lua_block {
ngx.say('<p>Hello World</p>')
}
}
}
}" > /root/openresty_work/conf/nginx.conf # [root@localhost openresty_work]# sh openresty_nginx_conf.sh
# [root@localhost openresty_work]# ls -lF conf/nginx.conf
# -rw-r--r-- root root Oct : conf/nginx.conf
# [root@localhost openresty_work]# nginx -s stop
# [root@localhost openresty_work]# nginx -p
# [root@localhost openresty_work]# nginx -p .
# [root@localhost openresty_work]# curl localhost:
# <p>Hello World</p>
# 在上述配置中, content_by_lua_file 指令用于引入外部文件, lua_code_cache 用于开启或关闭 lua 文件缓存.
# 在默认情况下会对lua文件进行缓存以提高效率,而在开发环境可以临时关闭缓存以方便测试.
# [root@localhost openresty_work]# vi test_lua_nginx.sh
# [root@localhost openresty_work]# sh test_lua_nginx.sh #!/bin/bash
echo 'worker_processes 1;
error_log logs/error.log;
events {
worker_connections ;
}
http {
server {
listen ;
location /test.lua{
lua_code_cache off;
content_by_lua_file test.lua;
}
}
}' > /root/openresty_work/conf/nginx.conf # [root@localhost openresty_work]# echo "ngx.say('<h1>hi,my name is kings-dev.</h1>')" > test.lua
# [root@localhost openresty_work]# cat test.lua
# ngx.say('<h1>hi,my name is kings-dev.</h1>')
# [root@localhost openresty_work]# nginx -p . -s reload
# nginx: [alert] lua_code_cache is off; this will hurt performance in ./conf/nginx.conf:
# [root@localhost openresty_work]# curl localhost:/test.lua
# <h1>hi,my name is kings-dev.</h1>
centos 7 OpenResty®(lua-nginx-module)搭建可扩展的Web平台的更多相关文章
- 用lua nginx module搭建一个二维码
用lua nginx module搭建一个二维码(qr code)生成器 作者 vinoca 發布於 2014年10月31日 如果有VPS,或者开源的路由器,安装一个nginx,添加lua-nginx ...
- CentOS 环境下基于 Nginx uwsgi 搭建 Django 站点
因为我的个人网站 restran.net 已经启用,博客园的内容已经不再更新.请访问我的个人网站获取这篇文章的最新内容,CentOS 环境下基于 Nginx uwsgi 搭建 Django 站点 以下 ...
- Centos 7 Docker、docker-compose、Registrator、Consul、Consul Template和Nginx实现高可扩展的Web框架
安装所需软件 Docker Docker-compose 配置docker-compose.yml文件内容如下: #load balancer will automatically update th ...
- CentOS安装OpenResty(Nginx+Lua)开发环境
一.简介 OpenResty® 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库.第三方模块以及大多数的依赖项.用于方便地搭建能够处理超高并发.扩展性极高 ...
- nginx 与 lua 开发环境搭建
首先下载最新版的 相关软件 的安装文件. nginx: http://nginx.org/en/download.html LuaJIT: http://luajit.org/download.htm ...
- OpenResty:通过 Lua 扩展 NGINX 实现的可伸缩的 Web 平台
关于 http://openresty.org/cn/about.html 这个开源 Web 平台主要由章亦春(agentzh)维护.在 2011 年之前曾由淘宝网赞助,在后来的 2012 ~ 201 ...
- 通过 Lua 扩展 NGINX 实现的可伸缩的 Web 平台OpenResty®
OpenResty® 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库.第三方模块以及大多数的依赖项.用于方便地搭建能够处理超高并发.扩展性极高的动态 W ...
- nginx整合php+lua+oracle环境搭建
nginx整合php+lua+oracle环境搭建 标签: nginxluaoraclephplinux -- : 1473人阅读 评论() 收藏 举报 分类: 技术() 版权声明:本文为博主原创文章 ...
- 在阿里云 CentOS 服务器(ECS)上搭建 nginx + mysql + php-fpm 环境
阿里云的云服务器(ECS)可以选择多种操作系统,打算用它运行 Drupal或者 WordPress ,你最好选择 Linux 系统,这篇文章的演示是基于阿里云的 CentOS 操作系统的服务器.我们在 ...
随机推荐
- 3、inform (通知、告诉、报告) - perform (表现)
- Mybatis Guide
每个基于MyBatis的应用都是以一个SqlSessionFactory的实例为中心的.SqlSessionFactory的实例可以通过SqlSessionFactoryBuilder获得.而SqlS ...
- 【转】java获取当前年、月、日 、小时 、分钟、 秒、 毫秒
public class Test { /** * 英文简写(默认)如:2010-12-01 */ public static String FORMAT_SHORT = "yyyy-MM- ...
- OSS上传图片demo
demo整理来源https://help.aliyun.com/document_detail/32011.html /** * 示例说明 * <p> * HelloOSS是OSS Jav ...
- 小米6使用charles抓包https
1. 下载charles 地址: https://zhubangbang.com/charles-crack-version-free-download-and-install-tutorial.ht ...
- 一、linux基础命令
一. 常用系统工作命令 1.echo 命令 echo命令用于在终端输出字符串或者变量提取后的值 echo $SHELL 2.date命令 date命令用于显示及设置系统的时间或者日期 参数 ...
- Java-Redis 热部署问题
项目请求时报错: java.lang.ClassCastException: cn.xingaohbd.seckil.model.User cannot be cast to cn.xingaohbd ...
- VUE 1.0
现代开发模式:vue/react. 20%的时间花在了表现层 传统开发模式:jquery. 80%的时间花在了表现层 MVC——数据.表现.行为分离 视图层(表现层)<----->数据层 ...
- 7.编写mapreduce案例
在写一个mapreduce类之前先添加依赖包 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=&qu ...
- 【LOJ】#3123. 「CTS2019 | CTSC2019」重复
LOJ3123 60pts 正难则反,熟练转成总方案数减掉每个片段都大于等于s的字典序的方案 按照一般的套路建出kmp上每个点加一个字符的转移边的图(注意这个图开始字母必须是nxt链中下一个相邻的字符 ...