• ubuntu安装openresty


    ubuntu安装openresty

    在线安装

    你可以在你的 Ubuntu 系统中添加 APT 仓库,这样就可以便于未来安装或更新我们的软件包(通过 apt-get update 命令)。 运行下面的命令就可以添加仓库(每个系统只需要运行一次):

    步骤一:安装导入 GPG 公钥时所需的几个依赖包(整个安装过程完成后可以随时删除它们):

    sudo apt-get -y install --no-install-recommends wget gnupg ca-certificates
    
    • 1

    步骤二:导入我们的 GPG 密钥:

    • ubuntu 16 ~ 20 版本

      wget -O - https://openresty.org/package/pubkey.gpg | sudo apt-key add -
      
      • 1
    • ubuntu 22 及以上版本

      wget -O - https://openresty.org/package/pubkey.gpg | sudo gpg --dearmor -o /usr/share/keyrings/openresty.gpg
      
      • 1

    步骤三:添加我们官方 APT 仓库。

    对于 x86_64amd64 系统,可以使用下面的命令:

    • ubuntu 16 ~ 20 版本

      echo "deb http://openresty.org/package/ubuntu $(lsb_release -sc) main" \
      | sudo tee /etc/apt/sources.list.d/openresty.list
      
      • 1
      • 2
    • ubuntu 22 及以上版本

      echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/openresty.gpg] http://openresty.org/package/ubuntu $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/openresty.list > /dev/null
      
      • 1

    而对于 arm64aarch64 系统,则可以使用下面的命令:

    • ubuntu 16 ~ 20 版本

      echo "deb http://openresty.org/package/arm64/ubuntu $(lsb_release -sc) main" \
      | sudo tee /etc/apt/sources.list.d/openresty.list
      
      • 1
      • 2
    • ubuntu 22 及以上版本

      echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/openresty.gpg] http://openresty.org/package/arm64/ubuntu $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/openresty.list > /dev/null
      
      • 1

    步骤四:更新 APT 索引:

    sudo apt-get update
    
    • 1

    然后就可以像下面这样安装软件包,比如 openresty

    sudo apt-get -y install openresty
    
    • 1

    这个包同时也推荐安装 openresty-opmopenresty-restydoc 包,所以后面两个包会缺省安装上。 如果你不想自动关联安装,可以用下面方法关闭自动关联安装:

    sudo apt-get -y install --no-install-recommends openresty
    
    • 1

    参阅 OpenResty Deb 包 页面获取这个仓库里头更多可用包的信息。

    Hello World 实例

    安装成功后,我们就可以使用 openresty 直接输出 html 页面。

    首先我们可以创建一个工作目录:

    mkdir /data/openresty/www
    cd /data/openresty/www/
    mkdir logs/ conf/
    
    • 1
    • 2
    • 3

    其中 logs 目录用于存放日志,conf 用于存放配置文件。

    接着,我们在 conf 目录下创建一个 nginx.conf 文件 代码如下:

    worker_processes  1;
    error_log logs/error.log;
    events {
        worker_connections 1024;
    }
    http {
        server {
            listen 9000;
            location / {
                default_type text/html;
                content_by_lua '
                    ngx.say("

    Hello, World!

    ") '
    ; } } }
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    如果你熟悉 nginx 的配置,应该对以上代码就很熟悉。这里我们将 html 代码直接写在了配置文件中。

    启动 openresty

    默认情况下 openresty 安装在 /usr/local/openresty 目录中,启动命令为:

    cd /home/www
    /usr/local/openresty/nginx/sbin/nginx -p `pwd`/ -c conf/nginx.conf
    
    • 1
    • 2

    如果没有任何输出,说明启动成功,-p 指定我们的项目目录,-c 指定配置文件。

    接下来我们可以使用 curl 来测试是否能够正常范围:

    curl http://localhost:9000/
    
    • 1

    输出结果为:

    Hello, World!

    • 1

    或者通过浏览器访问 http://localhost:9000/:

    image-20221102232153707

  • 相关阅读:
    深入flink系列——集群启动流程
    PostgreSQL数据库统计信息——analyze统计信息收集
    加密市场进入寒冬,是“天灾”还是“人祸”?
    39.JavaScript中Promise的基本概念、使用方法,回调地狱规避、链式编程
    Rviz插件分析(status_panel)
    浮动面试题
    git学习笔记
    用检索做时间序列预测是一种怎样的体验
    【力扣每日一题】2023.9.27 餐厅过滤器
    IDEA 快捷键记录【个人向】
  • 原文地址:https://blog.csdn.net/qq_36213352/article/details/127815985