nginx:“server”指令在这里是不允许的

我重新configurationnginx,但我不能得到它重新启动使用以下configuration:

CONF:

server { listen 80; server_name www.example.com; return 301 $scheme://example.com$request_uri; } server { listen 80; server_name example.com; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; location /robots.txt { alias /oath/to/robots.txt; access_log off; log_not_found off; } location = /favicon.ico { access_log off; log_not_found off; } location / { proxy_pass_header Server; proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 30; proxy_read_timeout 30; proxy_pass http://127.0.0.1:8000; } location /static { expires 1M; alias /path/to/staticfiles; } } 

运行sudo nginx -c conf -ttestingconfiguration下面的错误被返回我找不出什么是真正的问题

 nginx: [emerg] "server" directive is not allowed here in /etc/nginx/sites-available/config:1 nginx: configuration file /etc/nginx/sites-available/config test failed 

这不是一个nginx配置文件。 它是nginx配置文件的一部分。

nginx配置文件(通常称为nginx.conf )将如下所示:

 events { ... } http { ... server { ... } } 

server块被包含在一个http块中。

配置通常分布在多个文件中,通过使用include指令来引入额外的片段(例如从sites-enabledsites-enabled目录)。

使用sudo nginx -t来测试完整的配置文件,该配置文件从nginx.conf开始,并使用include指令引入额外的片段。 请参阅此文档了解更多