软件简介:
OpenResty (也称为 ngx_openresty)是一个全功能的 Web 应用服务器,它打包了标准的 Nginx 核心,很多的常用的第三方模块,以及它们的大多数依赖项。
OpenResty 通过汇聚各种设计精良的 Nginx 模块,
从而将 Nginx 有效的变成一个强大的 Web 应用服务器,
这样, Web 开发人员可以使用 Lua 脚本语言调动 Nginx 支持的各种C以及Lua 模块,
快速构造出足以胜任 10K+ 并发连接响应的超高性能Web 应用系统.
OpenResty 的目标是让你的Web服务直接跑在 Nginx 服务内部,
充分利用 Nginx 的非阻塞 I/O 模型,
不仅仅对 HTTP 客户端请求,甚至于对远程后端诸如
MySQL,PostgreSQL,~Memcaches 以及 ~Redis 等都进行一致的高性能响
http://openresty.org/cn/index.html
1.建立nginx运行用户和程序目录:
groupadd www
useradd -s /sbin/nologin -g www www
mkdir -p /usr/local/nginx
mkdir -p /usr/local/pcre
2.软件包下载(目前最稳定版本):
wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.32/pcre-8.32.zip
wget http://agentzh.org/misc/nginx/ngx_openresty-1.4.3.6.tar.gz
3.软件安装
3.1:安装pcre-8.32
mkdir -p /usr/local/pcre
unzip pcre-8.32.zip
cd pcre-8.32
./configure --prefix=/usr/local/pcre --enable-utf8 --enable-pcregrep-libbz2 --enable-pcregrep-libz
make && make install
3.2:安装ngx_openresty
tar -xvf ngx_openresty-1.4.3.6.tar.gz
cd ngx_openresty-1.4.3.6
./configure --user=www --group=www --prefix=/usr/local/ --with-pcre --user=www --group=www --with-luajit --with-file-aio --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module --with-pcre=/workspace/pcre-8.32 --with-cc-opt=' -O3'
gmake
gmake install
/etc/init.d/nginx reload
4.nginx调用lua测试配置文件
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#access_log logs/host.access.log main;
location /echo {
default_type 'text/plain';
echo 'hello echo';
}
location /lua {
default_type 'text/plain';
content_by_lua 'ngx.say("hello, lua")';
}
}
}
5.nginx 启动文件内容
#! /bin/sh
# chkconfig: 2345 55 25
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
# run 'update-rc.d -f nginx defaults', or use the appropriate command on your
# distro. For CentOS/Redhat run: 'chkconfig --add nginx'
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
### END INIT INFO
# Author: licess
# website: http://lnmp.org
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
PIDFILE=/usr/local/nginx/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
$DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}
do_stop() {
kill -INT `cat $PIDFILE` || echo -n "nginx not running"
}
do_reload() {
kill -HUP `cat $PIDFILE` || echo -n "nginx can't reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
do_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
do_stop
echo "."
;;
reload|graceful)
echo -n "Reloading $DESC configuration..."
do_reload
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
do_stop
do_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac
exit 0
6,安装报错:
6.1
[root@localhost conf]# /usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
解决方法:在/lib中创建一个symbol link到/usr/local/lib/libpcre.so.1
[root@localhost conf]# ln -s /usr/local/lib/libpcre.so.1 /lib
若出现如下信息,则表示配置正确,否则需按错误提示进行配置文件更正
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
6.2、启动Nginx服务
#/usr/local/nginx/sbin/nginx
出现告警信息:
nginx: [warn] the "log_format" directive may be used only on "http" level in /usr/local/nginx/conf/nginx.conf:
这是新版本的问题,需要我们将log_format的定义放到server的前面。如果你是直接更改的nginx.conf文件,你会发现这一句原本就是在server的前面的。