openresty(nginx) 配置禁止 IP 直接访问

准备好工作目录

mkdir work
cd work
mkdir conf logs

准备好 conf/nginx.conf 配置文件

worker_processes  1;
error_log logs/error.log;

events {
    worker_connections 1024;
}

http {
    lua_package_path '$prefix/lua/?.lua;';
    lua_code_cache on;

    server {
        listen 80;
        server_name domain1.com www.domain1.com;

        location ~ ^/api/([-_a-zA-Z0-9/]+) {
            access_by_lua_file lua/access_check.lua;

            content_by_lua_file lua/$1.lua;
        }

        location / {
            default_type text/html;
            content_by_lua_block {
                ngx.say("<p>hello, world</p>")
            }
        }
    }

    server {  ## 禁止 IP 直接访问
        listen 80 default_server;
        server_name _;
        return 500;
    }
}

openresty 启动

cd work
openresty -p `pwd` -c conf/nginx.conf

-p 指定工作目录
-c 指定配置文件

reload 配置文件也要带上启动时的 -p -c

openresty -p `pwd` -c conf/nginx.conf -s reload

猜你喜欢

转载自www.cnblogs.com/hangj/p/11499084.html