nginx: [emerg] "stream" directive is not allowed here

Hello,

I'm trying to stand up kubernetes using centos7. I skipped the enabling HTTP health checks, but stuck on setting up the front API load balancer. 

I included the "include" statement in the master nginx.conf file as its own section (like http), but when i reload it keeps giving me this error below.  

nginx: [emerg] "stream" directive is not allowed here in /etc/nginx/tcpconf.d/kubernetes.conf:1




  • post-author-pic
    Keith T
    10-26-2018

    Do you have the `stream` block at the very top context of the nginx.conf file? Feel free to paste in your nginx.conf. This error would indicate that it is nested within a different context which isn't allowed.

  • post-author-pic
    joezinho7
    10-26-2018

    Thank you so much for your response. 


    user nginx;

    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;

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

    }



  • post-author-pic
    joezinho7
    10-26-2018

    Could you further explain if it is nested?

  • post-author-pic
    Will B
    10-29-2018

    Change this:

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

    to this:
    }
    include /etc/nginx/conf.d/*.conf;

     
    You have the include nested (which means inside the "}"), but it should not be. Just move it outside "}" and it should work!

  • post-author-pic
    joezinho7
    10-29-2018

    It isn't liking the default.conf file... 


    [user@joezinho76 ~]$ sudo nginx -s reload 

    nginx: [emerg] "server" directive is not allowed here in /etc/nginx/conf.d/default.conf:1


    ___________________________________________________________________


    server {

    listen 80;

    server_name localhost;

    #charset koi8-r;

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

    location / {

    root /usr/share/nginx/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 /usr/share/nginx/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;

    #}

    }


  • post-author-pic
    Will B
    10-30-2018

    Try doing the nginx.conf like this:

    user nginx;

    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;

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

    }

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



  • post-author-pic
    joezinho7
    10-30-2018


  • post-author-pic
    joezinho7
    10-30-2018


  • post-author-pic
    joezinho7
    10-30-2018

    Thanks!  Configuration file worked, but when I reloaded and curled to port 6443 I received a connection error.


    [user@joezinho76 ~]$ sudo nginx -s reload

    [user@joezinho76 ~]$ curl -k https://localhost:6443/version

    curl: (7) Failed connect to localhost:6443; Connection refused


    _____________________________________________
    So I decided to restart the nginx service and it wouldn't start and gave me this error.

    Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

    ___________________________________________________


    Then I checked the status...

    _____________________________________________

    [user@joezinho76 ~]$ sudo systemctl status nginx

    ● nginx.service - nginx - high performance web server

    Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)

    Active: failed (Result: exit-code) since Tue 2018-10-30 15:14:21 UTC; 10s ago

    Docs: http://nginx.org/en/docs/

    Process: 1845 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)

    Process: 1858 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=1/FAILURE)

    Main PID: 1801 (code=exited, status=0/SUCCESS)

    Oct 30 15:14:21 joezinho76.mylabserver.com systemd[1]: Starting nginx - high performance web server...

    Oct 30 15:14:21 joezinho76.mylabserver.com nginx[1858]: nginx: [emerg] bind() to 0.0.0.0:6443 failed (13: Permission denied)

    Oct 30 15:14:21 joezinho76.mylabserver.com systemd[1]: nginx.service: control process exited, code=exited status=1

    Oct 30 15:14:21 joezinho76.mylabserver.com systemd[1]: Failed to start nginx - high performance web server.

    Oct 30 15:14:21 joezinho76.mylabserver.com systemd[1]: Unit nginx.service entered failed state.

    Oct 30 15:14:21 joezinho76.mylabserver.com systemd[1]: nginx.service failed.

    [user@joezinho76 ~]$




  • post-author-pic
    joezinho7
    10-30-2018

    Thanks Will and Keith for your help! I finally can curl... it was selinux... 

  • post-author-pic
    Will B
    10-31-2018

    Awesome! Glad to hear its working!

Looking For Team Training?

Learn More