Centos7安装Openresty 通过yum安装
在 /etc/yum.repos.d/ 下新建 OpenResty.repo 内容
[openresty] name=Official OpenResty Repository baseurl=https://copr-be.cloud.fedoraproject.org/results/openresty/openresty/epel-$releasever-$basearch/ skip_if_unavailable=True gpgcheck=1 gpgkey=https://copr-be.cloud.fedoraproject.org/results/openresty/openresty/pubkey.gpg enabled=1 enabled_metadata=1 查看可用的openresty软件
yum --disablerepo="*" --enablerepo="openresty" list available 当前安装的是 openresty.x86_64 版本1.11.2.2-8.el7.centos, 内置的openssl 是 1.0.2j
安装
yum install openresty -y 默认会安装到 /usr/local/openresty/ 目录下, 目录下包含了 luajit, lualib, nginx, openssl, pcre, zlib 这些组件
如果安装时显示Require GeoIP, 需要先安装geoip后再安装openresty
yum install epel-release yum --enablerepo=epel install geoip 使用命令行直接启动 /usr/local/openresty/nginx/sbin/nginx -c /usr/local/openresty/nginx/conf/nginx.conf
OpenResty安装时, 已经把路径加入了/usr/bin, 并且添加了服务 /etc/init.d/openresty, 可以通过服务脚本启动 systemctl start/stop/status openresty 可以通过-p参数设置工作目录, 对应nginx的conf, html, log都可以放到这个目录下 openresty -p /opt/my-fancy-app/ 防火墙检查和配置 # 查看状态 systemctl status firewalld # 查看开放的端口 firewall-cmd --zone=public --list-all # 添加80端口 firewall-cmd --permanent --zone=public --add-port=80/tcp firewall-cmd --reload 设置lua配置 #cd /usr/local/openresty/nginx/conf/ #vim nginx.conf #user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; 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;
###################################################### lua_package_path "/usr/local/openresty/lualib/?.lua;;"; lua_package_cpath "/usr/local/openresty/lualib/?.so;;"; include lua.conf; ###################################################### server { listen 80; server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
} 创建lua.conf #vim lua.conf server { listen 80; server_name _; #HelloWorld location /lua { default_type 'text/html'; content_by_lua 'ngx.say("hello world182.11")'; } } 创建lua目录 #mkdir /usr/local/openresty/nginx/html/lua 重启服务 #/etc/init.d/openresty restart 测试