Nginx_luajit安装

Nginx_luajit安装

    • 下载地址
    • Nginx安装
    • 配置
      • 配置nginx.conf
      • 编写一个lua脚本文件在nginx/conf目录下
      • 在nginx/conf目录下创建一个vhost的文件夹

下载地址

Nginx安装

  • 安装依赖
yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel
  • 安装pcre
下载 PCRE 安装包,下载地址: http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gztar zxvf pcre-8.35.tar.gz
cd pcre-8.35
./configure
make && make install
pcre-config --version
  • 安装LuaJit
http://luajit.org/download.html
tar zxvf LuaJIT-2.0.2.tar.gz
cd LuaJIT-2.0.2
make install PREFIX=/usr/local/luajit
echo "/usr/local/luajit/lib" > /etc/ld.so.conf.d/usr_local_luajit_lib.conf
export LUAJIT_LIB=/usr/local/luajit/lib
export LUAJIT_INC=/usr/local/luajit/include/luajit-2.0
可能需要
ln -s /usr/local/luajit/lib/libluajit-5.1.so.2 /usr/lib64/libluajit-5.1.so.2
  • 安装ngx_devel_kit
wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz
tar -xzvf v0.3.0.tar.gz
  • 安装lua-nginx-module
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.8.tar.gz
tar -xzvf v0.10.8.tar.gz
  • 安装Nginx
wget http://nginx.org/download/nginx-1.14.1.tar.gz
tar -xzvf nginx-1.14.1.tar.gz
cd nginx-1.14.1
./configure --prefix=/app/nginx --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.42 --with-zlib=/usr/local/src/zlib-1.2.11 --with-openssl=/usr/local/src/openssl-1.1.0g --add-module=/opt/soft/ngx_devel_kit-0.3.0 --add-module=/opt/soft/lua-nginx-module-0.10.8
make -j 2
make install

配置

配置nginx.conf

user nginx nginx;
worker_processes  1;#error_log  logs/error.log;
#error_log  logs/error.log  notice;
error_log  logs/error.log  info;pid        nginx.pid;
worker_rlimit_nofile 65535;events {use epoll;worker_connections  1024;
}http {include       mime.types;default_type  application/octet-stream;server_names_hash_max_size 1024;server_names_hash_bucket_size 128;client_header_buffer_size 64k;large_client_header_buffers 4 32k;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_nodelay   on;server_tokens off;keepalive_timeout  90;output_buffers 1 32k;proxy_connect_timeout  75;proxy_read_timeout 600;proxy_send_timeout 600;proxy_buffer_size 64k;proxy_buffers 8 64k;proxy_busy_buffers_size 128k;proxy_temp_file_write_size 128k;gzip  on;gzip_min_length  1k;gzip_buffers  4 16k;gzip_http_version 1.1;gzip_comp_level 6;gzip_types text/plain application/x-javascript text/css application/xml text/xml;gzip_vary on;server {listen       127.0.0.1:8883;server_name  localhost;charset utf-8;root /usr/local/nginx/html;access_log off;location /favicon.ico {log_not_found off;access_log off;}}include /usr/local/nginx/conf/vhost/*.conf;
}

编写一个lua脚本文件在nginx/conf目录下

  • file.fresh00air.top.access_by.lua

    -- local headers = ngx.req.get_headers()
    -- if headers['Host'] ~= 'file.fresh00air.top' then
    if ngx.var.http_host ~= 'file.fresh00air.top' thenngx.exit(ngx.HTTP_FORBIDDEN)return
    end
    

在nginx/conf目录下创建一个vhost的文件夹

  • 创建一个www.conf配置文件
    server{listen 80;server_name file.fresh00air.top;root /app/www;access_log off;allow all;#deny all;access_by_lua_file 'conf/file.fresh00air.top.access_by.lua';
    }
    

这样就可以使用lua脚本来过滤host了
其他具体的lua脚本方法和参数可以参考网上的配置
最后 nginx -s reload


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部