OpenResty

编译环境

# yum groupinstall "Development Tools"
yum -y install gcc gcc-c++ autoconf automake make
yum -y install zlib zlib-devel openssl pcre libxml2 libxml2-devel
yum -y install readline-devel pcre-devel openssl-devel

编译安装

V=1.9.3.1 \
&& cd /usr/local/src \
&& ( [ -f "ngx_openresty-$V.tar.gz" ] || wget https://openresty.org/download/ngx_openresty-$V.tar.gz ) \
&& rm -rf ngx_openresty-$V \
&& tar zxvf ngx_openresty-$V.tar.gz \
&& cd ngx_openresty-$V \
&& ./configure \
--prefix=/usr/local/openresty \
--http-log-path=/var/log/openresty/access.log \
--error-log-path=/var/log/openresty/error.log \
--http-client-body-temp-path=/var/cache/openresty/client_temp \
--http-proxy-temp-path=/var/cache/openresty/proxy_temp \
--http-fastcgi-temp-path=/var/cache/openresty/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/openresty/uwsgi_temp \
--http-scgi-temp-path=/var/cache/openresty/scgi_temp \
--pid-path=/var/run/openresty.pid \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-http_ssl_module \
--with-cc-opt='-O2 -g' \
--with-luajit \
--without-lua_redis_parser \
--without-lua_rds_parser \
--without-lua_resty_dns \
--without-lua_resty_memcached \
--without-lua_resty_redis \
--without-lua_resty_mysql \
--without-lua_resty_upload \
--without-lua_resty_upstream_healthcheck \
--without-lua_resty_string \
--without-lua_resty_websocket \
--without-lua_resty_lock \
--without-lua_resty_lrucache \
--without-lua_resty_core \
--without-http_xss_module \
--without-http_coolkit_module \
--without-http_set_misc_module \
--without-http_form_input_module \
--without-http_encrypted_session_module \
--without-http_srcache_module \
--without-http_headers_more_module \
--without-http_array_var_module \
--without-http_memc_module \
--without-http_redis2_module \
--without-http_redis_module \
--without-http_rds_json_module \
--without-http_rds_csv_module \
&& make -j2 \
&& make install

基本配置

[ -f /usr/sbin/nginx ] && mv /usr/sbin/nginx{,.backup}
ln -sfT /usr/local/openresty/nginx/sbin/nginx /usr/sbin/nginx

mkdir -p /usr/local/openresty/nginx/conf/{sites-available,sites-enabled}
mkdir -p /var/cache/openresty/

cat > /etc/logrotate.d/openresty <<EOF
/var/log/openresty/*.log {
    daily
    missingok
    rotate 30
    compress
    notifempty
    dateext
    sharedscripts
    postrotate
        [ -f /var/run/openresty.pid ] && kill -USR1 \`cat /var/run/openresty.pid\`
    endscript
} 
EOF

cd /usr/local/openresty/nginx/conf/sites-available \
&& cat > default.conf <<EOF
#default site
server {
    listen 80 default;
    #server_name default;
    root /usr/local/nginx/html;
    index index.html index.htm;
 
    #charset gb2312,utf-8,gbk;
 
    #autoindex on;
    #autoindex_exact_size off;
    #autoindex_localtime on;
 
    access_log /var/log/openresty/access.log main;
    error_log /var/log/openresty/error.log warn;

    location /nginx_status {
        stub_status on;
        access_log off;
        #allow 127.0.0.1;
        #allow 172.17.10.0/24;
        #deny all;
    }

} #end server
EOF
cd /usr/local/openresty/nginx/conf/sites-enabled \
&& ln -sfT ../sites-available/default.conf default.conf