OpenResty服務部署

一、環境

cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core)
nginx version:openresty/1.13.6.2

二、OpenResty安裝

[root@localhost ~]# yum install yum-fastestmirror     #更新源
[root@localhost ~]# yum update
[root@localhost ~]# 

三、OpenResty所需依賴的包安裝

[root@localhost ~]# yum install gcc gcc-c++ libreadline-dev libncurses5-dev libpcre3-dev libssl-dev pcre pcre-devel zlib zlib-devel openssl openssl-devel readline-devel  perl -y

下載nginx_upstream_check_module模塊,該模塊用於ustream健康檢查

[root@localhost ~]# wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/v0.3.0.tar.gz
[root@localhost ~]# tar -zxvf v0.3.0.tar.gz

下載ngx_cache_purge模塊,該模塊用於清理nginx緩存

[root@localhost ~]#  wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
[root@localhost ~]#  tar zxvf ngx_cache_purge-2.3.tar.gz

四、編譯安裝OpenResty

[root@localhost tools]# wget https://openresty.org/download/openresty-1.13.6.2.tar.gz
[root@localhost tools]# tar -zxvf openresty-1.13.6.2.tar.gz
[root@localhost tools]# cd openresty-1.13.6.2
[root@localhost openresty-1.13.6.2]# groupadd www
[root@localhost openresty-1.13.6.2]# useradd -M -g www -s /sbin/nologin www
[root@localhost openresty-1.13.6.2]#  ./configure --prefix=/usr/local/OpenResty --user=www --group=www --with-luajit --without-http_redis2_module --with-http_iconv_module --with-http_realip_module --with-pcre --with-luajit --add-module=/home/tools/ngx_cache_purge-2.3/ --add-module=/home/tools/nginx_upstream_check_module-0.3.0/ --with-http_stub_status_module --with-http_ssl_module -j2
[root@localhost openresty-1.13.6.2]# gmake && gmake install
[root@localhost openresty-1.13.6.2]# cd /app/OpenResty/nginx/sbin/
[root@localhost sbin]# [root@mysql sbin]# ./nginx -V
nginx version: openresty/1.13.6.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/OpenResty/nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.3.0 --add-module=../iconv-nginx-module-0.14 --add-module=../echo-nginx-module-0.61 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2rc3 --add-module=../set-misc-nginx-module-0.32 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.08 --add-module=../srcache-nginx-module-0.31 --add-module=../ngx_lua-0.10.13 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.33 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.19 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.15 --add-module=../rds-csv-nginx-module-0.09 --add-module=../ngx_stream_lua-0.0.5 --with-ld-opt=-Wl,-rpath,/usr/local/OpenResty/luajit/lib --user=www --group=www --with-http_realip_module --with-pcre --add-module=/home/tools/ngx_cache_purge-2.3 --add-module=/home/tools/nginx_upstream_check_module-0.3.0 --with-http_stub_status_module --with-http_ssl_module --with-stream --with-stream_ssl_module

五、將OpenResty配置成服務,設置開機啓動

[root@localhost nginx]# vim /lib/systemd/system/nginx.service
[Unit]                 #服務的說明
Description=nginx      #描述服務
After=network.target   #描述服務類別

[Service]              #服務運行參數的設置
Type=forking           #後臺運行的形式,
ExecStart=/usr/local/OpenResty/nginx/sbin/nginx             #服務的具體運行命令
ExecReload=/usr/local/OpenResty/nginx/sbin/nginx reload     #重啓命令
ExecStop=/usr/local/OpenResty/nginx//sbin/nginx quit        #停止命令
PrivateTmp=true        #給服務分配獨立的臨時空間

[Install]
WantedBy=multi-user.target
[root@localhost nginx]# systemctl enable nginx
nginx.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig nginx on
[root@localhost nginx]#

六、OpenResty配置文件

[root@localhost tools]# cd /usr/local/OpenResty/nginx/conf
[root@localhost conf]# cp nginx.conf{,.bak}
[root@localhost conf]# vim nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

七、測試是否搭建成功
在這裏插入圖片描述
瀏覽器出現以上信息說明成功!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章