• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

安装并配置OpenResty

武飞扬头像
她的名字叫李承利
帮助1

1、OpenResty介绍:OpenResty 并不是一个全新的 Web 服务器,而是基于 Nginx,它利用了 Nginx 模块化、可扩展的特性,开发了一系列的增强模块,并把它们打包整合,形成了一个"一站式”的 Web 开发平台"。

        虽然 OpenResty 的核心是 Nginx,但又不同于Nginx,关键就在于其中的 ngx_lua 模块,把 Lua 语言嵌入到了 Nginx,可以用脚本的方式操作 Nginx 内部的进程、多路复用、阶段式处理等各种构件。

2、OpenResty安装:

        1>、安装依赖包:

[root@node1 ~]# yum install readline-devel pcre-devel openssl-devel -y

        2>、添加OpenResty仓库:

  1.  
    [root@node1 ~]# yum install yum-utils -y
  2.  
     
  3.  
    [root@node1 ~]# yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo

        3>、安装OpenResty:

  1.  
    [root@node1 ~]# yum install openresty -y
  2.  
     
  3.  
    ##安装openresty命令工具包
  4.  
    [root@node1 ~]# yum install openresty-resty -y

以上操作默认将OpenResty安装在" /usr/local/openresty "。

3、配置OpenResty:

        1>、创建nginx组和用户:

  1.  
    [root@node1 ~]# groupadd nginx
  2.  
     
  3.  
    [root@node1 ~]# useradd -g nginx -s /sbin/nologin -M nginx

        2>、修改nginx配置文件:

  1.  
    [root@node1 ~]# vim /usr/local/openresty/conf/nginx.conf
  2.  
     
  3.  
    #user nobody;
  4.  
    worker_processes 1;
  5.  
     
  6.  
    ##规定访问失败的日志路径
  7.  
    error_log logs/error.log;
  8.  
    #error_log logs/error.log notice;
  9.  
    #error_log logs/error.log info;
  10.  
     
  11.  
    #pid logs/nginx.pid;
  12.  
     
  13.  
     
  14.  
    events {
  15.  
    worker_connections 1024;
  16.  
    }
  17.  
     
  18.  
     
  19.  
    http {
  20.  
    include mime.types;
  21.  
    default_type application/octet-stream;
  22.  
     
  23.  
    ##规定日志格式
  24.  
    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  25.  
    '$status $body_bytes_sent "$http_referer" '
  26.  
    '"$http_user_agent" "$http_x_forwarded_for"';
  27.  
     
  28.  
    #access_log logs/access.log main;
  29.  
     
  30.  
    sendfile on;
  31.  
    #tcp_nopush on;
  32.  
     
  33.  
    #keepalive_timeout 0;
  34.  
    keepalive_timeout 65;
  35.  
     
  36.  
    #gzip on;
  37.  
     
  38.  
    server {
  39.  
    listen 80;
  40.  
    server_name localhost;
  41.  
     
  42.  
    #charset koi8-r;
  43.  
     
  44.  
    ##规定访问成功的日志路径
  45.  
    access_log logs/host.access.log main;
  46.  
    ##将访问成功的日志输送到指定主机的指定端口,并打上"access_log"标记
  47.  
    #access_log 127.0.0.1511,tag=access_log;
  48.  
     
  49.  
    location / {
  50.  
    root html;
  51.  
    index index.html index.htm;
  52.  
    }
  53.  
     
  54.  
    #error_page 404 /404.html;
  55.  
     
  56.  
    # redirect server error pages to the static page /50x.html
  57.  
    #
  58.  
    error_page 500 502 503 504 /50x.html;
  59.  
    location = /50x.html {
  60.  
    root html;
  61.  
    }
  62.  
    }
  63.  
    }
学新通

4、启动OpenResty服务:

  1.  
    ####将openresty设置临时成环境变量
  2.  
    [root@node1 ~]# export PATH=$PATH:/usr/local/openresty/bin/openresty
  3.  
     
  4.  
    ##将openresty设置永久成环境变量
  5.  
    [root@node1 ~]# echo "export PATH=$PATH:/usr/local/openresty/bin/openresty" >> /etc/profile
  6.  
    [root@node1 ~]# source /etc/profile ##加载文件,使其立即生效
  7.  
     
  8.  
    ##检查openresty配置语法是否正确
  9.  
    [root@node1 ~]# openresty -t
  10.  
     
  11.  
    ##重启openresty服务
  12.  
    [root@node1 ~]# openresty -s reload
  13.  
     
  14.  
    ##检查openresty nginx配置文件语法是否正确
  15.  
    [root@node1 ~]# /usr/local/openresty/nginx/sbin/nginx -t
  16.  
     
  17.  
    ##重启openresty nginx服务,单独启动nginx
  18.  
    [root@node1 ~]# /usr/local/openresty/nginx/sbin/nginx -s reload
  19.  
     
  20.  
    ##也可以通过systemctl来进行操作
  21.  
    [root@node1 ~]# systemctl start openresty.service
  22.  
    [root@node1 ~]# systemctl status openresty.service
学新通

5、确认服务是否启动:

学新通

浏览器访问机器80端口:

学新通

 监控日志文件是否有日志保存:

学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhggaffg
系列文章
更多 icon
同类精品
更多 icon
继续加载