2

I'm pretty new to server administration and I'm having a huge headache trying to fix a nginx conf file that just won't work in a Debian remote machine. Whenever I try to debug the file doing nginx -c sites-enabled/estadaodados.com -t, i end up with this answer:

nginx: [emerg] "server" directive is not allowed here in /etc/nginx/sites-enabled/estadaodados.com:1

This is my nginx.conf file:

user www-data;
worker_processes 2;
pid /var/run/nginx.pid;

events {
  worker_connections 768;
  multi_accept on;
  use epoll;
}

http {    
  set_real_ip_from 127.0.0.1;
  real_ip_header X-Forwarded-For;
  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  keepalive_timeout 20;
  client_max_body_size 15m;
  client_body_timeout 60;
  client_header_timeout 60;
  client_body_buffer_size  1K;
  client_header_buffer_size 1k;
  large_client_header_buffers 4 8k;
  send_timeout 60;
  reset_timedout_connection on;
  types_hash_max_size 2048;
  server_tokens off;
  server_names_hash_bucket_size 64;
  include /etc/nginx/mime.types;
  default_type application/octet-stream;
  access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log;
  log_format main '$remote_addr - $remote_user [$time_local] '
  '"$request" $status $body_bytes_sent "$http_referer" '
  '"$http_user_agent" "$http_x_forwarded_for"';

  gzip on;
  gzip_static on;
  gzip_disable "MSIE [1-6].*(MSIE?.*SV1)";
  gzip_vary on;
  gzip_proxied any;
  gzip_comp_level 6;
  gzip_min_length 512;
  gzip_buffers 16 8k;
  gzip_http_version 1.1;
  gzip_types text/css text/javascript text/xml text/plain text/x-component application/javascript application/x-javascript application/json application/xml application/rss+xml font/truetype application/x-font-ttf font/opentype application/vnd.ms-fontobject image/svg+xml;

  # Virtual Host Configs
  include /etc/nginx/sites-enabled/*;
}

And this is my conf file that's in the sites-enabled folder (i just deleted all the old and extensive config but even this small block of code still doesn't work) :

server {                                                                                                                                                                                                                                                                                                                                                     
  server_name estadaodados.com;
  listen *:80;
  root /home/edados/www/main;
  port_in_redirect off;
  server_tokens off;
  autoindex off;
  index index.html index.htm index.php;
}

What is it that I'm missing?

rodrigoburg
  • 21
  • 1
  • 3

1 Answers1

1

While debugging nginx config you need to provide path for main nginx.conf file which starts with http block. As you are directly provided yours vhost config to nginx -t its throwing error.

You should do nginx -c /path/to/nginx.conf -t.

Harshad
  • 121
  • 2