yaoweibin / nginx_tcp_proxy_module

add the feature of tcp proxy with nginx, with health check and status monitor
http://yaoweibin.github.com/nginx_tcp_proxy_module
1.64k stars 366 forks source link

TCP block: "return" directive is not allowed #148

Open david92rl opened 7 years ago

david92rl commented 7 years ago

Hi, I'm trying to create a default TCP server to send a 444 code but I'm getting this message:

nginx: [emerg] "return" directive is not allowed here in /etc/nginx/nginx.conf:48

I've configured nginx with the following:

./configure \
    --with-http_ssl_module \
    --add-module=/srv/nginx_tcp_proxy_module \
    --prefix=/usr/share/nginx \
    --sbin-path=/usr/sbin/nginx \
    --conf-path=/etc/nginx/nginx.conf \
    --pid-path=/var/run/nginx.pid \
    --lock-path=/var/lock/nginx.lock \
    --error-log-path=/var/log/nginx/error.log \
    --http-log-path=/var/log/access.log \
    --user=www-data \
    --group=www-data

And my nginx.conf (line 48 is inside tcp block):

user  www-data;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    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"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;
    server_tokens off;

    server {
        listen 80 default_server;
        return 444;
    }
    server {
        listen 443 default_server;
        return 444;
    }

    include /etc/nginx/conf.d/*.conf;
}

tcp {
    access_log  /var/log/nginx/tcp_access.log;

    server {
        listen 54545 default;
        return 444;
    }

    include /etc/nginx/tcpconf.d/*.conf;
}

I'm not sure if I'm missing something in the configure process.

Thanks

xiaokai-wang commented 7 years ago

It‘s not supported in the 'tcp' block.

david92rl commented 7 years ago

So, is there any way to deny connections in the tcp block when the server_name doesn't match?

OmarBasem commented 3 years ago

any solutions?

yaoweibin commented 2 years ago

No, it should not be use return in this module, It's just a tcp proxy module.

Omar Basem @.***> 于2021年6月26日周六 下午6:39写道:

any solutions?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/yaoweibin/nginx_tcp_proxy_module/issues/148#issuecomment-868982580, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABFRGJKWQVV7PCDZYSPYN3TUWU5RANCNFSM4CWJQPKQ .