首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >/etc/nginx/nginx.conf中的未知指令"server“:4

/etc/nginx/nginx.conf中的未知指令"server“:4
EN

Stack Overflow用户
提问于 2012-06-07 23:15:42
回答 5查看 49.1K关注 0票数 15

对于nginx/0.7.65,我在第4行得到了这个错误。为什么它不能识别server

代码语言:javascript
复制
#### 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;
}
EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2012-06-07 23:21:07

http模块的上下文中必须包含server指令。此外,您还缺少顶层events模块,该模块有一个强制设置,以及配置的http模块中的一大堆节。虽然nginx documentation在从头开始创建配置方面没有特别的帮助,但还是有working examples的。

来源:nginx documentation on server directive

票数 28
EN

Stack Overflow用户

发布于 2016-06-17 18:34:04

添加一个顶级条目可以解决这个问题:

代码语言:javascript
复制
events {  }
票数 11
EN

Stack Overflow用户

发布于 2019-01-21 00:26:55

尝试调整配置文件的行尾和编码。在我的例子中,需要ANSI编码和可能的"Linux style“行结尾(只需要LF符号,不需要 CRLF符号)。

我知道这是一个相当古老的问题。然而,被接受的答案( server指令必须包含在http模块的上下文中)的建议可能会令人困惑,因为有很多示例(在Nginx网站和this guide中) server指令是,而不是http模块的上下文中包含的

sd z (“我重写了*.conf文件,它工作了”)的答案可能来自相同的原因:有一个.config文件具有错误的编码或行尾,该文件被重写后被更正。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10934705

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档