user3332404
user3332404

Reputation: 171

Nginx Error ("http" directive is not allowed here in /etc/nginx/sites-enabled/abc)

I am geeting below error while starting Nginx service

"http" directive is not allowed here in /etc/nginx/sites-enabled/abc:1

Here is my abc config

worker_processes  1;
error_log /usr/local/openresty/nginx/logs/lua.log debug;
events {
  worker_connections 1024;
}
http {
  upstream kibana {
    server server1:30001;
    server server2:30001;
    keepalive 15;
  }
  server {
    listen 8882;
    location / {
        ssl_certificate /etc/pki/tls/certs/ELK-Stack.crt;
        ssl_certificate_key /etc/pki/tls/private/ELK-Stack.key;
        ssl_session_cache shared:SSL:10m;
        auth_basic "Restricted Access";
        auth_basic_user_file /etc/nginx/htpasswd.users;
      proxy_pass http://kibana;
      proxy_redirect off;
      proxy_buffering off;
      proxy_http_version 1.1;
      proxy_set_header Connection "Keep-Alive";
      proxy_set_header Proxy-Connection "Keep-Alive";
    }
  }
}

--> FYI I am creating this file in /etc/nginx/sites-available and linking it to /etc/nginx/sites-enabled . I am providing a link using following command

sudo ln -s /etc/nginx/sites-available/abc /etc/nginx/sites-enabled/abc

After the above command I can see a link is been created in /etc/nginx/sites-enabled directory .

Please suggest what I am doing wrong ?

Regards,

Upvotes: 0

Views: 8004

Answers (1)

Zartch
Zartch

Reputation: 1025

The http directive dos not belong there.

In the ngnix.conf you have already the http directive

http {
    ..config logs ...
    inclide etc/ngnix/sites-enabled/*;  <--- This Line include your files
    .. more config...
    server {
       (..default server ...)
       location / {
           index 
           root 
       }
    }
}

The files in your sites enabled must only contain servers, the http directive is in the principal configuration. I would try:

events {
  worker_connections 1024;
}

  upstream kibana {
    server server1:30001;
    server server2:30001;
    keepalive 15;
  }

    error_log /usr/local/openresty/nginx/logs/lua.log debug;

    listen 8882;
    location / {
        basic "Restricted Access";
        auth_basic_user_file /etc/nginx/htpasswd.users;
      proxy_pass http://kibana;
      proxy_redirect off;
      proxy_buffering off;
      proxy_http_version 1.1;
      proxy_set_header Connection "Keep-Alive";
      proxy_set_header Proxy-Connection "Keep-Alive";
    }

    ssl_certificate /etc/pki/tls/certs/ELK-Stack.crt;
    ssl_certificate_key /etc/pki/tls/private/ELK-Stack.key;
    ssl_session_cache shared:SSL:10m;

}

Upvotes: 2

Related Questions