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 操作系统的服务器.我们在 ...
随机推荐
- Python中webbrowser的用法
#coding:utf-8 import time import webbrowser as web import os import random #随机选择一个浏览器打开网页 def open_u ...
- SSIS数据同步实践
SSIS数据同步实践 背景 在已初步验证不同实例下同构表数据同步方案之后,为了实现数据持续同步,需使用SSIS把之前的生成脚本和执行脚本的两个步骤组合在一起部署成包之后,通过JOB定时去执行: 测 ...
- coreDNS一直处于创建中解决
https://blog.csdn.net/gsying1474/article/details/53256599 执行: [root@lab1 coredns]# kubectl delete -f ...
- tcp协议相关概念
conv 会话IDmtu 最大传输单元mss 最大分片大小state 连接状态(0xFFFFFFFF表示断开连接)snd_una 第一个未确认的包snd_nxt 待发送包的序号rcv_nxt 待接收消 ...
- 【笔记】7天玩转容器&CKA管理员实训
第一部分 day1,容器基础知识介绍 安装 apt-get install docker-engine [root@cce-7day-fudonghai-24106 01CNL]# docker -v ...
- 关于Spring的BeanUtils
文章<用Spring的BeanUtils前,建议你先了解这几个坑>里面,作者最后得到了这几个结论: 1.Spring得BeanUtils得CopyProperties方法需要对应得属性有g ...
- 【JAVA开发】eclipse最新版本Eclipse Neon
这个版本的IDE支持Java.JavaScript.C/C++.PHP和Fortran等多种编程语言: 这个版本首次鼓励用户使用Eclipse Installer来做安装,这是一种由Eclipse O ...
- smoothscroll
smoothscroll是一款jQuery插件,可以平滑地滚动到指定的地方. 可以解决chrome锚点失效的问题. 官方网站 http://iamdustan.com/smoothscroll/ gi ...
- Linux 脚本
1.理解Linux Shell和基本Shell脚本语言的小贴士(一) http://blog.jobbole.com/63952/ ------伯乐在线
- [目标检测] 从 R-CNN 到 Faster R-CNN
R-CNN 创新点 经典的目标检测算法使用滑动窗法依次判断所有可能的区域,提取人工设定的特征(HOG,SIFT).本文则预先提取一系列较可能是物体的候选区域,之后仅在这些候选区域上用深度网络提取特征, ...