Skip to content
WONGCW 網誌
  • 首頁
  • 論壇
  • 微博
  • 壁紙下載
  • 免費圖床
  • 視頻下載
  • 聊天室
  • SEO工具
  • 支援中心
  • 表格製作
  • More
    • 在線名片
    • 網頁搜索
    • 天氣預報
    • 二維碼生成器
    • WordPress 插件及主題下載
  • Search Icon

WONGCW 網誌

記錄生活經驗與點滴

基于 CentOS 快速搭建 OpenResty

基于 CentOS 快速搭建 OpenResty

2018-09-29 Comments 0 Comment

了解 OpenResty®

任务时间:1min ~ 3min

本教程适用于 64 位版本的 CentOS 6.x 和 7.x

什么是 OpenResty®

OpenResty® 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库、第三方模块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性极高的动态 Web 应用、Web 服务和动态网关。

OpenResty® 通过汇聚各种设计精良的 Nginx 模块(主要由 OpenResty 团队自主开发),从而将 Nginx 有效地变成一个强大的通用 Web 应用平台。这样,Web 开发人员和系统工程师可以使用 Lua 脚本语言调动 Nginx 支持的各种 C 以及 Lua 模块,快速构造出足以胜任 10K 乃至 1000K 以上单机并发连接的高性能 Web 应用系统。

OpenResty® 的目标是让你的Web服务直接跑在 Nginx 服务内部,充分利用 Nginx 的非阻塞 I/O 模型,不仅仅对 HTTP 客户端请求,甚至于对远程后端诸如 MySQL、PostgreSQL、Memcached 以及 Redis 等都进行一致的高性能响应。

更新系统

任务时间:1min ~ 3min

在安装前,我们先对 CVM 的系统进行更新,确保系统内的软件源和工具是最新版本。

执行命令从软件源进行更新

sudo yum update -y

安装 OpenResty®

任务时间:3min ~ 10min

添加官方仓库

sudo yum install yum-utils
sudo yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo

安装二进制包

sudo yum install openresty

在安装过程中如果看到如下提示,请在确认签名最后8位是 [D5EDEB74] 的情况下,输入 y 并回车确认。

Retrieving key from https://openresty.org/package/pubkey.gpg
Importing GPG key 0xD5EDEB74:
 Userid     : "OpenResty Admin <admin@openresty.com>"
 Fingerprint: e522 18e7 0878 97dc 6dea 6d6d 97db 7443 d5ed eb74
 From       : https://openresty.org/package/pubkey.gpg
Is this ok [y/N]: y

不区分大小写

以默认配置文件启动

在安装了官方的二进制包之后,这个包自动帮我们生成了一份配置文件,可以让我们直接启动服务,并确认服务是否启动成功。

执行如下命令启动 openresty 服务

对于 CentOS 6.x 的用户:

sudo service openresty start

对于 CentOS 7.x 的用户:

sudo systemctl start openresty

确认服务启动成功

接下来就可以直接通过 IP 访问服务器上已经启动的 openresty 服务了。

打开这个链接:http://<您的 CVM IP 地址>/

如果看到 Welcome to OpenResty! 的欢迎页面,则说明服务启动成功!

欢迎页面

设置开机自动启动

默认情况下,openresty 可能不会开机启动。我们需要告诉系统开机自动启动 openresty 服务。

执行如下命令设置开机自动启动

对于 CentOS 6.x 的用户:

sudo chkconfig openresty on

对于 CentOS 7.x 的用户:

sudo systemctl enable openresty

配置 OpenResty®

任务时间:1min ~ 3min

查看现有的配置文件

在安装、启动完成之后,我们就可以尝试对 openresty 的配置文件进行个性化修改了。

默认安装完成后,配置文件存放在 /usr/local/openresty/nginx/conf/,我们可以使用 vim nano 文本编辑器打开配置文件并进行编辑,或直接在实验室的 Web 页面进行编辑。

请选择你熟悉的编辑器

nano /usr/local/openresty/nginx/conf/nginx.conf
vim /usr/local/openresty/nginx/conf/nginx.conf

查看 nginx.conf

编辑配置文件修改监听端口

现在我们来尝试修改一下默认配置文件。首先我们来对 Nginx 的监听端口做一个修改。我们将默认的 80 端口监听修改到 8080 端口。

编辑 nginx.conf

示例代码:/usr/local/openresty/nginx/conf/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;

    server {
        listen       8080;
        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;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

检查配置文件有效性

在修改了配置文件之后,我们不要着急重新启动 openresty 服务,而是应该先对配置文件进行校验,确保配置文件不存在语法错误。

以下两个命令都可以对配置文件进行检查:

sudo service openresty configtest
/usr/local/openresty/nginx/sbin/nginx -t

对于第一个命令,没有任何输出就是检查通过。对于第二个命令,显示如下内容为检查通过:

nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test is successful

如果配置文件存在语法问题,如缺少结尾分号,则会有错误信息进行提示:

nginx: [emerg] directive "worker_processes" is not terminated by ";" in /usr/local/openresty/nginx/conf/nginx.conf:12
nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test failed

重新加载配置文件

确认配置文件不存在语法问题等错误后,就可以重新加载配置文件了。可以使用以下两个命令实现:

sudo service openresty reload
/usr/local/openresty/nginx/sbin/nginx -s reload

重新加载成功时,第一个命令会输出类似信息(根据系统版本可能有所不同):

Reloading openresty configuration: [  OK  ]

第二个命令不会有任何输出。

如果加载失败,则会有对应的错误信息显示。

访问修改后的服务

接下来就可以直接通过修改后的端口来访问 openresty 服务了。

打开这个链接:http://<您的 CVM IP 地址>:8080/

完成实验

恭喜!您已经成功完成了使用包管理工具安装 OpenResty 的实验任务

分享此文:

  • 分享到 Twitter(在新視窗中開啟)
  • 按一下以分享至 Facebook(在新視窗中開啟)
  • 分享到 WhatsApp(在新視窗中開啟)
  • 按一下以分享到 Telegram(在新視窗中開啟)
  • 分享到 Pinterest(在新視窗中開啟)
  • 分享到 Reddit(在新視窗中開啟)
  • 按一下即可分享至 Skype(在新視窗中開啟)
  • 按一下即可以電子郵件傳送連結給朋友(在新視窗中開啟)
  • 點這裡列印(在新視窗中開啟)

相關


Linux資訊, 教學資源

Post navigation

PREVIOUS
Linux 下部署 Django 环境
NEXT
基于 Ubuntu 快速搭建 OpenResty

發表迴響 取消回覆

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料。

More results...

Generic filters
Exact matches only
Search in title
Search in content
Search in excerpt
Filter by 分類
網站公告
Featured
限時免費
ESET NOD32
WINDOWS 10 &11 INSIDER PREVIEW
Windows 軟件下載
系統軟件
辦公軟件
圖像處理
影音媒體
網絡軟件
應用軟件
Mac 軟件下載
安卓軟件下載
網絡資訊
Mac資訊
Linux資訊
VPS資訊
NASA資訊
金融資訊
WhatsApp Stickers教學
WordPress資訊
WeChat資訊
PHP資訊
Plesk資訊
TensorFlow
教學資源
開源程序
網頁工具
SEO工具
醫療健康
旅遊及消閒
其他資訊
Content from
Content to
2018 年 9 月
一 二 三 四 五 六 日
 12
3456789
10111213141516
17181920212223
24252627282930
« 8 月   10 月 »

分類

  • 網站公告
  • 限時免費
  • ESET NOD32
  • WINDOWS 10 &11 INSIDER PREVIEW
  • Windows 軟件下載
  • 系統軟件
  • 辦公軟件
  • 圖像處理
  • 影音媒體
  • 網絡軟件
  • 應用軟件
  • Mac 軟件下載
  • 安卓軟件下載
  • 網絡資訊
  • Mac資訊
  • Linux資訊
  • VPS資訊
  • NASA資訊
  • WhatsApp Stickers教學
  • WordPress資訊
  • WeChat資訊
  • PHP資訊
  • Plesk資訊
  • TensorFlow
  • 教學資源
  • 開源程序
  • 網頁工具
  • SEO工具
  • 醫療健康
  • 旅遊及消閒
  • 其他資訊

彙整

近期文章

  • 保姆級教程12306官方詳解如何用積分“免費坐高鐵” 2023-03-31
  • 挖礦毫無意義NVIDIA解釋為何賣礦卡:客戶願意花錢我們管不著 2023-03-31
  • 吃日料、聽京劇庫克時隔3年再訪中國 2023-03-31
  • 華為淨現金下滑至1763億元孟晚舟稱財務狀況依然穩健 2023-03-31
  • 任天堂Switch 2不會遠了開發者已收到新主機開發工具 2023-03-31
  • NASA太陽動力學觀測站捕捉到從太陽爆發的強烈耀斑 2023-03-31
  • 科學家發現製造原子級薄金屬層的簡單方法 2023-03-31
  • 華為發布2022年年度報告孟晚舟現場談壓力和信心 2023-03-31
  • 不要錯過:NASA將於4月3日揭曉Artemis II登月宇航員 2023-03-31
  • 新藥可”二合一”治療心力衰竭和睡眠呼吸障礙 2023-03-31

熱門文章與頁面︰

  • DP vs HDMI 誰才是遊戲玩家最佳選擇?
  • Autodesk AutoCAD 2021 正式版註冊版-簡體/繁體中文/英文版
  • ESET NOD32 LICENSE KEY (UPDATED 2023-01-17)
  • 打車叫到特斯拉不會開門很尷尬?官方介紹開關門方法
  • Explorer Patcher:讓Windows 11恢復Windows 10的行為特徵
  • 盜版Windows 7還能免費升級Windows 10嗎?
  • 世界上有多少個國家
  • 38歲985文科碩士被迫送外賣本人再發聲:已脫下孔乙己長衫應聘道士被拒
  • NVIDIA H100 Hopper加速計算卡上市:配備80GB顯存價格超24萬元
  • 讓WIN10去強制縮放那些不支援DPI縮放的軟體或遊戲

投遞稿件

歡迎各界人士投遞稿件到admin@wongcw.com

請提供以下資料:

1.你的名字

2.你的電郵

3.分類目錄

4.文章標題

5.文章摘要

6.文章內容

7.文章來源

 

聯繫我們

查詢,投稿,商務合作:
​admin@wongcw.com
​技術支援:
​support@wongcw.com
​客户服務:
​cs@wongcw.com

QQ群:833641851

快帆

MALUS

極度掃描

DMCA.com Protection Status

WONGCW 網誌

  • 免責聲明
  • 捐助我們
  • ThemeNcode PDF Viewer
  • ThemeNcode PDF Viewer SC
  • Events

服務器提供

本站使用之服務器由ikoula提供。

聯繫我們

查詢,投稿,商務合作:
​admin@wongcw.com
​技術支援:
​support@wongcw.com
​客户服務:
​cs@wongcw.com

QQ群:833641851

© 2023   All Rights Reserved.