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 操作系统的服务器.我们在 ...
随机推荐
- vue3.x版本安装vue-cli建项目
vue-cli版本在3以上 全局安装vue-cli npm install -g @vue/cli 建立项目工程,假设项目建在e:\vueProject\vue-cli3.0+目录下: 先进入此目录: ...
- Python中类的继承代码实例
Python中类的继承代码实例 这篇文章主要介绍了Python中类的继承代码实例,本文直接给出代码及运行效果,需要的朋友可以参考下 相对于C 的继承编写,Python更简洁,而且效率也是很高的,下面编 ...
- 第九组 通信3班 063 自反ACL
一.拓扑图 R4为外网,R2和R3为内网. 二.地址表 Device Interface IP address R1 F 0/0 10.1.63.1 F 0/1 14.1.63.1 R2 F 0/0 ...
- 配置cinder-volume服务使用ceph作为后端存储
在ceph监视器上执行 CINDER_PASSWD='cinder1234!'controllerHost='controller'RABBIT_PASSWD='0penstackRMQ' 1.创建p ...
- C#_初识之HelloWorld
C#————是一个我很不愿意去碰的语言,但是还是得低头,巨硬还是巨硬....... ———————————————————————————————————————————————— 前几天在Githu ...
- vue中打包之后的dist文件不放在服务器的根目录下
在工作当中,我使用webpack打包的dist,由于管理的问题,无法被放在服务器根目录下 ,但在目前的vue配置,dist不放在根目录下,访问页面会成为一片空白,于是便要对vue框架的config进行 ...
- Centos7 安装Jenkins (rpm 方式)
首先说明本教程基于jenkins 2.183,但是其他版本基本差不多,主要说一下其中比较坑的几点,做一个总结. 1.rpm 包的下载 从官网上下载rpm的速度简直让人不能忍受,所以千万不要去官网下载. ...
- 【Python】【demo实验12】【练习实例】【列表的复制】
#!/usr/bin/python # encoding=utf-8 # -*- coding: UTF-8 -*- # 将一个列表复制到另外一个列表中: # 分析:可以使用[:] L = [0,3, ...
- django CBV装饰器 自定义django中间件 csrf跨站请求伪造 auth认证模块
CBV加装饰器 第一种 @method_decorator(装饰器) 加在get上 第二种 @method_decorator(login_auth,name='get') 加在类上 第三种 @met ...
- 关于python中的包,模块导入的问题详解(二)
from import导入 紧接着的是from xx import xx 语法 1 ################ 2 from my_moudule import name 3 print(na ...