Nginx+lua(openresty)开发环境搭建shell脚本,nginxopenresty


Nginx+lua(openresty)开发环境搭建,以及搭建的过程解释已有博客:https://blog.csdn.net/weixin_37998647/article/details/79826316

下面是自动搭建的脚本,采用的是直接杀死本机运行80端口的程序

#!/bin/bash
mkdir -p /usr/servers
cd /usr/servers/
yum install -y perl pcre-devel openssl openssl-devel gcc curl
wget http://openresty.org/download/ngx_openresty-1.7.7.2.tar.gz
tar -xzvf ngx_openresty-1.7.7.2.tar.gz
cd /usr/servers/bundle/LuaJIT-2.1-20150120/
make clean && make && make install
ln -sf luajit-2.1.0-alpha /usr/local/bin/luajit
cd /usr/servers/ngx_openresty-1.7.7.2/bundle
wget https://github.com/FRiCKLE/ngx_cache_purge/archive/2.3.tar.gz
tar -xvf 2.3.tar.gz
cd /usr/servers/ngx_openresty-1.7.7.2/bundle
wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/v0.3.0.tar.gz
tar -xvf v0.3.0.tar.gz
cd /usr/servers/ngx_openresty-1.7.7.2
./configure --prefix=/usr/servers --with-http_realip_module  --with-pcre  --with-luajit --add-module=./bundle/ngx_cache_purge-2.3/ --add-module=./bundle/nginx_upstream_check_module-0.3.0/ -j2
make && make install
cd /usr/servers/
A=`ls -l | grep luajit | awk -F " " '{print$9}'`
B=`ls -l | grep lualib | awk -F " " '{print$9}'`
if A="luajit" || B="lualib"
then
kill -9 `ps -ef | grep nginx | grep -v grep | awk -F " " '{print $2}'`
/usr/servers/nginx/sbin/nginx
openresty_status=`netstat -tnulp |grep nginx`
    if [ -n "$openresty_status" ];then
    echo "nginx 已启动!"
    else
    echo "nginx 未启动!"
    fi
fi
cat>/usr/servers/nginx/conf/nginx.conf<<EOF

#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;
    #include       lua.conf;
    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"';

    #lua模块路径,多个之间”;”分隔,其中”;;”表示默认搜索路径,默认到/usr/servers/nginx下找
    lua_package_path "/usr/servers/lualib/?.lua;;";  #lua 模块
    lua_package_cpath "/usr/servers/lualib/?.so;;";  #c模块
    include /usr/example/example.conf;

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        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;
    #    }
    #}

}
EOF
mkdir -p /usr/example/lua/
touch /usr/example/example.conf
touch /usr/example/lua/test.lua
cat>/usr/example/example.conf<<EOF
server {
    listen       80;
    server_name  _;

    location /lua {
        default_type 'text/html';
        lua_code_cache off;
        content_by_lua_file /usr/example/lua/test.lua;
    }
}
EOF
cat>/usr/example/lua/test.lua<<EOF
ngx.say("hello world,hello world");
ngx.say("The environment of 'nginx+lua' has been configured.");
EOF
/usr/servers/nginx/sbin/nginx -s reload

相关内容

    暂无相关文章