李斯特 发表于 2019-2-16 12:36:05

centos7通过yum安装Openresty

  Centos7安装Openresty
通过yum安装
  在 /etc/yum.repos.d/ 下新建 OpenResty.repo 内容
  
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
#usernobody;
worker_processes1;
#error_loglogs/error.log;
#error_loglogs/error.lognotice;
#error_loglogs/error.loginfo;
#pid      logs/nginx.pid;
events {
worker_connections1024;
}
http {
include       mime.types;
default_typeapplication/octet-stream;
#log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
**    #                  '$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" "$http_x_forwarded_for"';**

#access_loglogs/access.logmain;
sendfile      on;
#tcp_nopush   on;
  #keepalive_timeout0;
keepalive_timeout65;

#gzipon;
  ######################################################
lua_package_path "/usr/local/openresty/lualib/?.lua;;";
lua_package_cpath "/usr/local/openresty/lualib/?.so;;";
include lua.conf;
######################################################
server {
listen       80;
server_namelocalhost;

    #charset koi8-r;
#access_loglogs/host.access.logmain;
location / {
root   html;
indexindex.html index.htm;
}
#error_page404            /404.html;
  #error_page404            /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;
servername ;
#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
测试
http://i2.运维网.com/images/blog/201805/29/4f6342e5958950e29f85ee298f47228a.png



页: [1]
查看完整版本: centos7通过yum安装Openresty