Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unknown directive "server" in /etc/nginx/nginx.conf:4

Tags:

nginx

With nginx/0.7.65 I'm getting this error on line 4. Why doesn't it recognize server?

#### CHAT_FRONT ####

server {
  listen 7000 default deferred;
  server_name example.com;
  root /home/deployer/apps/chat_front/current/public;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}

#### CHAT_STORE ####

server {
  listen 7002 default deferred;
  server_name store.example.com;
  root /home/deployer/apps/chat_store/current/public;

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}

#### LOGIN ####

server {
  listen 7004 default deferred;
  server_name login.example.com;
  root /home/deployer/apps/login/current/public;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}

#### PERMISSIONS ####

server {
  listen 7006 default deferred;
  server_name permissions.example.com;
  root /home/deployer/apps/permissions/current/public;

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}

#### SEARCH ####

server {
  listen 7008 default deferred;
  server_name search.example.com;
  root /home/deployer/apps/search/current/public;

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}

#### ANALYTICS ####

server {
  listen 7010 default deferred;
  server_name analytics.example.com;
  root /home/deployer/apps/analytics/current/public;

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}
like image 973
Chris Avatar asked Jun 07 '12 15:06

Chris


3 Answers

The server directive must be contained in the context of http module. Additionally you are missing top-level events module, which has one obligatory setting, and a bunch of stanzas which are to be in the http module of your config. While nginx documentation is not particularly helpful on creating config from scratch, there are working examples there.

Source: nginx documentation on server directive

like image 72
Krzysztof Bujniewicz Avatar answered Oct 13 '22 20:10

Krzysztof Bujniewicz


Adding a top level entry got around the problem:

events {  }
like image 11
h4ck3rm1k3 Avatar answered Oct 13 '22 19:10

h4ck3rm1k3


Try to adjust line endings and the encoding of your configuration file. In my case ANSI encoding and possibly "Linux style" line endings (only LF symbols, not both CR and LF symbols) were required.

I know it is a rather old question. However the recommendation of the accepted answer (that the server directive must be contained in the context of http module) might confuse because there are a lot of examples (on the Nginx website also and in this Microsoft guide) where the server directive is not contained in the context of http module.

Possibly the answer of sd z ("I rewrote the *.conf file and it worked") comes from the same reason: there was a .config file with incorrect encoding or line endings which was corrected after the file has been rewrited.

like image 3
Hoborg Avatar answered Oct 13 '22 18:10

Hoborg