nginx.conf 中的 http 指令错误 [英] http directive error in nginx.conf

查看:63
本文介绍了nginx.conf 中的 http 指令错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的 /home/ubuntu/project/nginx.conf 的样子:

http {

    # configuration of the server
    server {
        # the port your site will be served on
        listen      80;
        # the domain name it will serve for
        server_name ec2-xxx-xxx-xxx-xxx.eu-central-1.compute.amazonaws.com; # substitute your machine's IP address or FQDN
        charset     utf-8;

        # max upload size
        client_max_body_size 75M;   # adjust to taste

        # Django media
        location /media  {
            alias /home/ubuntu/project/media;  # your Django project's media files - amend as required
        }

        location /static {
            alias /home/ubuntu/project/static; # your Django project's static files - amend as required
        }

        # Finally, send all non-media requests to the Django server.
        location / {
            uwsgi_pass  unix:///home/ubuntu/project/deploy/web.sock;;
            include     /home/ubuntu/project/deploy/uwsgi_params;
        }
    }
}

当我尝试启动 nginx 时,它向我抛出一个错误:"http" 指令在/etc/nginx/sites-enabled/nginx.conf:1 中是不允许的

When I try to start nginx, it throws me an error: "http" directive is not allowed here in /etc/nginx/sites-enabled/nginx.conf:1

我一直在阅读不同的帖子试图解决这个问题,但没有成功.我还提到,如果我删除 http { } (因此只保留服务器定义),它会起作用.我做错了什么?

I've been reading different posts trying to fix this but with no success. I also mention that If I remove http { } (so leaving only the server definition), it works. What am I doing wrong?

忘了说这个,我建了一个链接:

forgot to say this, I built a link:

sudo ln -s/home/ubuntu/project/nginx.conf/etc/nginx/sites-enabled/nginx.conf

推荐答案

服务器上的 /etc/nginx/nginx.conf 文件几乎肯定包含 include sites-enabled/*;

The /etc/nginx/nginx.conf file on the server almost certainly contains include sites-enabled/*;

include 语句简单地将引用文件的内容内联(递归),因此当 nginx 尝试启动时,结果配置将如下:

include statements simply put the contents of the referenced files inline (recursively) as such the resultant config when nginx tries to start will be along the lines of:

# contents of /etc/nginx/nginx.conf
...
http {
    ...
    # include sites-enabled/*;

    # contents of /etc/nginx/sites-enabled/nginx.conf
    http { # <----------------------   

        # configuration of the server
        server {
            ...
        }
    }
}

我做错了什么?

http 指令只能在主上下文中(即不在任何其他指令中)它不能在另一个 http 指令中,因此问题中描述的配置是一个致命错误.删除重复的 http 指令会产生一个有效的配置,允许 nginx 启动.

What am I doing wrong?

The http directive can only be in the main context (i.e. not inside any other directives) it cannot be inside another http directive hence the config described in the question is a fatal error. Removing the duplicate http directive results in a valid config, allowing nginx to start.

这篇关于nginx.conf 中的 http 指令错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆