【问题标题】:directive is not allowed here in /etc/nginx/default.d/app.conf:1 NGINX Config EC2/etc/nginx/default.d/app.conf:1 NGINX Config EC2 中不允许使用指令
【发布时间】:2021-02-25 01:55:28
【问题描述】:

我正在尝试将我的应用程序配置为在 ec2 上运行,但遇到了一些困难。 这是一个使用 docker-compose 构建的多容器应用程序,由 django、drf、channels、redis gunicorn、celery 和 nuxt 组成。

我有一个正在运行的实例,可以通过 SSH 连接到该实例并安装相关软件包、docker nginx docker-compose 等。

我不能做的是编辑我的 app.conf nginx 文件以使用公共 ip 33.455.234.23(示例 ip) 路由后端、休息和前端。

我已经创建了 app.conf nginx 文件,它在本地运行良好,但是当我尝试编辑 nginx 文件时 安装后将我的应用程序配置为公共 IP,我遇到了错误。 我在编写配置时遇到的错误是

2020/11/13 01:59:17 [emerg] 13935#0: "http" directive is not allowed here in /etc/nginx/default.d/app.conf:3
nginx: configuration file /etc/nginx/nginx.conf test failed

这是我的 nginx 配置

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include /etc/nginx/mime.types;
    client_max_body_size 100m;

    upstream asgiserver {
        server asgiserver:8000;
    }

    upstream nuxt {
        ip_hash;
        server nuxt:3000;
    }

    server {
        listen 80 default_server;
        server_name localhost;

        location ~ /(api|admin|static)/ {
            proxy_pass http://asgiserver;
            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-Host $host;
        }
   
        location /ws/ {
            proxy_pass   http://asgiserver;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            # proxy_redirect off;
        }
    
        location / {
            proxy_pass http://nuxt;
            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-Host $host;
        }
    }
}

我在这里做错了什么?为了让我的应用在我的 ec2 公共地址上通过反向代理运行,我需要做什么?

【问题讨论】:

  • 看起来您可能遗漏了一些关闭的}
  • @Red Cricket 这不是语法问题。我现在已经尝试了多个配置,并且在第一个块上出现了同样的错误
  • 不确定我是否理解 - 您是否尝试将公共 ip 连接到在特定端口(即端口 8000)上运行的 django 应用程序?

标签: django vue.js nginx amazon-ec2 nginx-reverse-proxy


【解决方案1】:

看起来这个配置文件没有被 nginx 当作主配置文件,而是包含在主主配置文件 /etc/nginx/nginx.conf 中,而 /etc/nginx/nginx.conf 又包含 http 块,其中包含 include 指令,像

include /default.d/*.conf;

勾选此项,如果为真,则从/etc/nginx/default.d/app.conf 文件中删除除上游和服务器配置块之外的所有内容。将client_max_body_size 指令移到server 块内。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-10
    • 2013-12-21
    • 1970-01-01
    相关资源
    最近更新 更多