最近,遇到一个问题,就是我们CMS系统制作的产品页面和产品列表页面,发布到nginx服务器上,因为业务要求,客户看到的链接必须是短链接,当前的做法就是在nginx的配置中通过rewrite的方式做的。这个是静态的做法,当业务要修改短链接或者有新产品发布的话,就存在问题,要运维人员去修改nginx的配置文件,若这个运维忘记了或者改错了,或者业务运营人员找不到运维人员,会是什么效果?404呗。

针对这个问题,我希望通过lua+nginx+redis的方式,动态的加载这些链接的映射关系。

openresty对lua以及nginx的诸多模块都有很好的封装,所以,我就要自己在测试环境下尝试下,基于openresty的lua功能,首先就是部署openresty。

1. 下载openresty。从官网下载最新的版本。本博文案例用到的是openresty-1.11.2.2.tar.gz

解压缩,首先,因为openresty(确切的说,是nginx)依赖pcre做正则引擎,还有要用openssl做安全引擎。所以,先要安装pcre和openssl。千万注意,要用源码,在安装openresty的时候,通过--with-<module>指定源码路径。

 [root@localhost openresty-1.11.2.2]# ./configure --prefix=/usr/local/openresty --with-pcre=/opt/pcre2-10.23 --with-openssl=/opt/openssl-1.1.0e
。。。。。。。
Configuration summary
+ using PCRE library: /opt/pcre2-10.23
+ using OpenSSL library: /opt/openssl-1.1.0e
+ 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

上面日志中可以看出来,我的pcre和openssl的版本。pcre是pcre2-10.23,openssl的版本是openssl-1.1.0e。

这时看上去一切ok,没问题,可以依据提示信息,执行gmake了。

2. 执行gmake

。。。。。。。。。。。。。。。
install apps/openssl -> /opt/openssl-1.1.0e/.openssl/bin/openssl
install ./tools/c_rehash -> /opt/openssl-1.1.0e/.openssl/bin/c_rehash
gmake[]: 离开目录“/opt/openssl-1.1.0e”
cc -c -I/opt/openresty-1.11.2.2/build/luajit-root/usr/local/openresty/luajit/include/luajit-2.1 -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -g -O2 -DNDK_SET_VAR -DNDK_UPSTREAM_LIST -DNDK_SET_VAR -DNDK_SET_VAR -DNDK_SET_VAR -DLUA_DEFAULT_PATH='"/usr/local/openresty/site/lualib/?.lua;/usr/local/openresty/site/lualib/?/init.lua;/usr/local/openresty/lualib/?.lua;/usr/local/openresty/lualib/?/init.lua"' -DLUA_DEFAULT_CPATH='"/usr/local/openresty/site/lualib/?.so;/usr/local/openresty/lualib/?.so"' -DNDK_SET_VAR -I src/core -I src/event -I src/event/modules -I src/os/unix -I ../ngx_devel_kit-0.3./objs -I objs/addon/ndk -I ../ngx_lua-0.10./src/api -I /opt/pcre2-10.23 -I /opt/openssl-1.1.0e/.openssl/include -I objs \
-o objs/src/core/nginx.o \
src/core/nginx.c
In file included from src/core/ngx_core.h::,
from src/core/nginx.c::
src/core/ngx_regex.h:15:18: 致命错误:pcre.h:没有那个文件或目录
#include <pcre.h>
^
编译中断。
gmake[]: *** [objs/src/core/nginx.o] 错误
gmake[]: 离开目录“/opt/openresty-1.11.2.2/build/nginx-1.11.”
gmake[]: *** [build] 错误
gmake[]: 离开目录“/opt/openresty-1.11.2.2/build/nginx-1.11.”
gmake: *** [all] 错误

gmake有问题,如上红色的错误显示,找不到pcre.h,我到/opt/pcre2-10.23/src下面看,的确没有这个文件,莫非是版本的问题?我果断的更换了一个pcre的版本,没有用pcre2,选择的是pcre-8.40.再次configure并gmake。

。。。。。。。。。。。。。。。  
-o objs/src/os/unix/ngx_linux_sendfile_chain.o \
src/os/unix/ngx_linux_sendfile_chain.c
cc -c -I/opt/openresty-1.11.2.2/build/luajit-root/usr/local/openresty/luajit/include/luajit-2.1 -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -g -O2 -DNDK_SET_VAR -DNDK_UPSTREAM_LIST -DNDK_SET_VAR -DNDK_SET_VAR -DNDK_SET_VAR -DLUA_DEFAULT_PATH='"/usr/local/openresty/site/lualib/?.lua;/usr/local/openresty/site/lualib/?/init.lua;/usr/local/openresty/lualib/?.lua;/usr/local/openresty/lualib/?/init.lua"' -DLUA_DEFAULT_CPATH='"/usr/local/openresty/site/lualib/?.so;/usr/local/openresty/lualib/?.so"' -DNDK_SET_VAR -I src/core -I src/event -I src/event/modules -I src/os/unix -I ../ngx_devel_kit-0.3./objs -I objs/addon/ndk -I ../ngx_lua-0.10./src/api -I /opt/pcre-8.40 -I /opt/openssl-1.1.0e/.openssl/include -I objs \
-o objs/src/event/ngx_event_openssl.o \
src/event/ngx_event_openssl.c
src/event/ngx_event_openssl.c: 在函数‘ngx_ssl_connection_error’中:
src/event/ngx_event_openssl.c:2048:21: 错误:‘SSL_R_NO_CIPHERS_PASSED’未声明(在此函数内第一次使用)
|| n == SSL_R_NO_CIPHERS_PASSED /* 182 */

^
src/event/ngx_event_openssl.c::: 附注:每个未声明的标识符在其出现的函数内只报告一次
gmake[]: *** [objs/src/event/ngx_event_openssl.o] 错误
gmake[]: 离开目录“/opt/openresty-1.11.2.2/build/nginx-1.11.”
gmake[]: *** [build] 错误
gmake[]: 离开目录“/opt/openresty-1.11.2.2/build/nginx-1.11.”
gmake: *** [all] 错误

这次看来,没有pcre的那个头文件找不到的问题了,走的更远一步了,这次报错是openssl有问题,这个就不是那么简单好查看了,去网络上查看吧,找到原因,是因为openssl的API改动很大,对应openresty的使用,我选择了老版本的openssl,将当前的1.1.0e版本的改成1.0.1u的了。再次configure并gamke。

。。。。。。。。。。。。。
objs/addon/src/ngx_http_rds_csv_output.o \
objs/ngx_modules.o \
-L/opt/openresty-1.11.2.2/build/luajit-root/usr/local/openresty/luajit/lib -Wl,-rpath,/usr/local/openresty/luajit/lib -Wl,-E -ldl -lpthread -lcrypt -L/opt/openresty-1.11.2.2/build/luajit-root/usr/local/openresty/luajit/lib -lluajit-5.1 -lm -ldl /opt/pcre-8.40/.libs/libpcre.a /opt/openssl-1.0.1u/.openssl/lib/libssl.a /opt/openssl-1.0.1u/.openssl/lib/libcrypto.a -ldl -lz \
-Wl,-E
sed -e "s|%%PREFIX%%|/usr/local/openresty/nginx|" \
-e "s|%%PID_PATH%%|/usr/local/openresty/nginx/logs/nginx.pid|" \
-e "s|%%CONF_PATH%%|/usr/local/openresty/nginx/conf/nginx.conf|" \
-e "s|%%ERROR_LOG_PATH%%|/usr/local/openresty/nginx/logs/error.log|" \
< docs/man/nginx. > objs/nginx.
gmake[]: 离开目录“/opt/openresty-1.11.2.2/build/nginx-1.11.”
gmake[]: 离开目录“/opt/openresty-1.11.2.2/build/nginx-1.11.”

这次,没有openssl的问题了。gmake的过程ok。

3. gmake install

。。。。。。。。。。
gmake[]: 进入目录“/opt/openresty-1.11.2.2/build/nginx-1.11.”
gmake -f objs/Makefile install
gmake[]: 进入目录“/opt/openresty-1.11.2.2/build/nginx-1.11.”
test -d '/usr/local/openresty/nginx' || mkdir -p '/usr/local/openresty/nginx'
test -d '/usr/local/openresty/nginx/sbin' \
|| mkdir -p '/usr/local/openresty/nginx/sbin'
test ! -f '/usr/local/openresty/nginx/sbin/nginx' \
|| mv '/usr/local/openresty/nginx/sbin/nginx' \
'/usr/local/openresty/nginx/sbin/nginx.old'
cp objs/nginx '/usr/local/openresty/nginx/sbin/nginx'
test -d '/usr/local/openresty/nginx/conf' \
|| mkdir -p '/usr/local/openresty/nginx/conf'
cp conf/koi-win '/usr/local/openresty/nginx/conf'
cp conf/koi-utf '/usr/local/openresty/nginx/conf'
cp conf/win-utf '/usr/local/openresty/nginx/conf'
test -f '/usr/local/openresty/nginx/conf/mime.types' \
|| cp conf/mime.types '/usr/local/openresty/nginx/conf'
cp conf/mime.types '/usr/local/openresty/nginx/conf/mime.types.default'
test -f '/usr/local/openresty/nginx/conf/fastcgi_params' \
|| cp conf/fastcgi_params '/usr/local/openresty/nginx/conf'
cp conf/fastcgi_params \
'/usr/local/openresty/nginx/conf/fastcgi_params.default'
test -f '/usr/local/openresty/nginx/conf/fastcgi.conf' \
|| cp conf/fastcgi.conf '/usr/local/openresty/nginx/conf'
cp conf/fastcgi.conf '/usr/local/openresty/nginx/conf/fastcgi.conf.default'
test -f '/usr/local/openresty/nginx/conf/uwsgi_params' \
|| cp conf/uwsgi_params '/usr/local/openresty/nginx/conf'
cp conf/uwsgi_params \
'/usr/local/openresty/nginx/conf/uwsgi_params.default'
test -f '/usr/local/openresty/nginx/conf/scgi_params' \
|| cp conf/scgi_params '/usr/local/openresty/nginx/conf'
cp conf/scgi_params \
'/usr/local/openresty/nginx/conf/scgi_params.default'
test -f '/usr/local/openresty/nginx/conf/nginx.conf' \
|| cp conf/nginx.conf '/usr/local/openresty/nginx/conf/nginx.conf'
cp conf/nginx.conf '/usr/local/openresty/nginx/conf/nginx.conf.default'
test -d '/usr/local/openresty/nginx/logs' \
|| mkdir -p '/usr/local/openresty/nginx/logs'
test -d '/usr/local/openresty/nginx/logs' \
|| mkdir -p '/usr/local/openresty/nginx/logs'
test -d '/usr/local/openresty/nginx/html' \
|| cp -R docs/html '/usr/local/openresty/nginx'
test -d '/usr/local/openresty/nginx/logs' \
|| mkdir -p '/usr/local/openresty/nginx/logs'
gmake[]: 离开目录“/opt/openresty-1.11.2.2/build/nginx-1.11.”
gmake[]: 离开目录“/opt/openresty-1.11.2.2/build/nginx-1.11.”
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

这么看来,openresty安装部署完毕,是不是要检查一下,openresty能否启用呢?先查看下openresty的文件目录结构,如下,含有lua的组件,测试lua,后续就靠它了。

[root@localhost openresty]# ll
总用量
drwxr-xr-x. root root 3月 : bin
drwxr-xr-x. root root 3月 : luajit
drwxr-xr-x. root root 3月 : lualib
drwxr-xr-x. root root 3月 : nginx
drwxr-xr-x. root root 3月 : pod
-rw-r--r--. root root 3月 : resty.index
drwxr-xr-x. root root 3月 : site

4.验证openresty是否安装成功

[root@localhost sbin]# pwd
/usr/local/openresty/nginx/sbin
[root@localhost sbin]# ./nginx
nginx: [emerg] bind() to 0.0.0.0: failed (: Address already in use)
nginx: [emerg] bind() to 0.0.0.0: failed (: Address already in use)
nginx: [emerg] bind() to 0.0.0.0: failed (: Address already in use)
nginx: [emerg] bind() to 0.0.0.0: failed (: Address already in use)
nginx: [emerg] bind() to 0.0.0.0: failed (: Address already in use)

报错,地址被占用了,看到这个第一时间想到的是这个机器上安装了基本版的nginx,于是乎,将openresty的nginx配置文件中listen的端口修改一下,不用默认的80,改成8090.重新启动nginx。这次没有地址被占用的错误了。在地址栏输入地址http://localhost:8090, 看到下面的内容,OK,部署完毕!

到此,openresty部署完毕,总结一下,这里的坑无外乎两点:

1》 openresty需要的pcre插件,不能用pcre2来代替。

2》 openssl的版本更替中,API的改动非常大,版本兼容有问题,openresty需要的openssl版本,一定要匹配。

解除上面两个坑之后,我的部署其实变成了openresty-1.11.2.2 + pcre-8.40 + openssl-1.0.1u

部署openresty遇到的一些坑的更多相关文章

  1. weblogic中部署SSH项目遇到的坑

    总结将SSH项目部署到weblogic遇到的坑.项目中是SSH,另外还用到了webservice.quartz等框架.在tomcat部署是可以的,现在总结部署到weblogic遇到的坑. 在这里说一下 ...

  2. Django项目在Linux服务器上部署和躺过的坑

    引言 在各方的推荐下,领导让我在测试环境部署之前开发的测试数据预报平台.那么问题来了,既然要在服务器上部署, 就需要准备: 1.linux服务器配置 2.linux安装python环境搭建与配置 3. ...

  3. OpenResty + Lua + Kafka 实现日志收集系统以及部署过程中遇到的坑

    ********************* 部署过程 ************************** 一:场景描述 对于线上大流量服务或者需要上报日志的nginx服务,每天会产生大量的日志,这些 ...

  4. Mono+Jexus部署C# MVC的各种坑

    如果你看到这篇文章,先别急着动手,过完一遍,确定是你要的再动手. 别人提到的这里不赘述,只说查了好久才知道的. 1号坑:System.IO.FileNotFoundException Could no ...

  5. 那些在BAE上部署node.js碰到的坑

    在BAE上使用node.js半年多了,其中碰到了不少因为BAE云环境限制碰到的坑 写下来大家碰到了,也不用那么麻烦的去看好几天代码了,直接对症下药 官方公布的坑有: BAE是使用package.jso ...

  6. Linux下部署MySQL,大小写敏感踩坑记录

    今天在将开发环境中的门户数据库复制到新环境后,使用SqlSugar的ORM框架进行数据库操作的时候,出现了主键找不到的现象.排查了很久终于发现了关键点.特此记录. 1.开发环境:    操作系统:CE ...

  7. 记录一次使用iisnode部署node项目遇到的坑!

    前言:最近因为项目原因,需要在IIS下部署node项目,在此之前,曾经部署过类似的项目,因此在这次部署还算比较顺利,只是在其中遇到了几个比较坑的问题,所以这次使用博客记录下来,如有园友遇到过类似问题, ...

  8. kubernetes 1.5.2 部署kube-dns 踩过的坑

    看了kubernetes 权威指南 遇见了dns这一块.于是便按照书上的方式部署了一下. 书上使用的方式是:kube2sky+etcd+skydns的方式.按照书上的yaml写了一遍,发现无论如何都无 ...

  9. Jenkins+tomcat自动发布的热部署/重启及遇到的坑解决办法

    一.背景 公司的项目一直手动maven打包.上传服务器.关闭/开启tomcat,整个流程下来耗时耗力,虽然可以将所有流程通过shell脚本一次性解决,但如果可以通过idea的Jenkins插件一键自动 ...

随机推荐

  1. Pandas分组统计函数:groupby、pivot_table及crosstab

    利用python的pandas库进行数据分组分析十分便捷,其中应用最多的方法包括:groupby.pivot_table及crosstab,以下分别进行介绍. 0.样例数据 df = DataFram ...

  2. Python基础5--字符串

    1 find().rfind().index().rindex().count() s = "this apple is red apple" s.find("apple ...

  3. Spring+CXF+Maven发布Webservice

    使用CXF发布WebService简单又快速,还可以与Spring集成,当Web容器启动时一起发布WebService服务.本例是简单的客户端给服务端发送订单信息,服务端返回订单转为json的字符串. ...

  4. 【Python】进程-锁(1)

    #第二题,做一个加减乘除的考试系统,自动出题,自动判对错,并统计结果,一次考试10道题 import random symbols=["+","-"," ...

  5. Dubbo浅谈

    一.高并发的解决 1.高并发:很多人同时访问. 2.高并发产生的性能瓶颈: tomcat支持的controller,解决办法:多个tomcat共同支撑.(tomcat集群) 只有一个service被调 ...

  6. JAVA多线程Thread与Runnable

    一.Runnable Runnable为一个之包含一个run方法的接口 public class MyRunnable implements Runnable{ @Override //表示:预示重写 ...

  7. ZOJ - 4081:Little Sub and Pascal's Triangle (结论)

    Little Sub is about to take a math exam at school. As he is very confident, he believes there is no ...

  8. Vue.js学习使用心得(一)

    一.初步了解 Vue.js是一套构建用户界面的渐进式框架,它只关注视图层, 采用自底向上增量开发的设计. Vue 的目标是通过尽可能简单的 API 实现响应的数据绑定和组合的视图组件,相当于JavaS ...

  9. linux 系统 目录,以部分及相关命令

    linux 系统里的文件类型有: b. d.l. c. -  .s (块设备.目录.软连接.数字串设备.普通文件(文本.二进行文件).socket文件 ) ls 命令 ls -a  查看当前目录下的所 ...

  10. 前端tab切换 和 validatejs表单验证插件

    一.tab切换 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...