本文介绍了nginx: [emerg] “服务器"此处不允许使用指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我已经重新配置了 nginx,但我无法使用以下配置重新启动它:

I have reconfigured nginx but i can't get it to restart using the following config:

配置:

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 /path/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 -t 来测试配置后,返回以下错误,我无法弄清楚真正的问题是什么

after running sudo nginx -c conf -t to test the configuration the following error is returned i can't figure out what is really the problem

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 配置文件的一部分.

That is not an nginx configuration file. It is part of an nginx configuration file.

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

The nginx configuration file (usually called nginx.conf) will look like:

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

server 块包含在 http 块中.

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

Often the configuration is distributed across multiple files, by using the include directives to pull in additional fragments (for example from the sites-enabled directory).

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

Use sudo nginx -t to test the complete configuration file, which starts at nginx.conf and pulls in additional fragments using the include directive. See this document for more.

这篇关于nginx: [emerg] “服务器"此处不允许使用指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 09:16