Skip to main content
 首页 » 编程设计

nginx: [emerg] "http"指令在/etc/nginx/sites-enabled/default:1 中是不允许的

2024年11月24日26me-sa

我是 NGINX 的新手,我正在尝试设置最少的工作。因此,我尝试使用 nginx 和主管运行 aiohttp 迷你应用程序(通过 this 示例)。但我无法正确配置 Nginx 并收到以下错误:

nginx: [emerg] "http" directive is not allowed here in /etc/nginx/sites-enabled/default:1 

这是完整的 default.conf 文件:
http { 
  upstream aiohttp { 
    # Unix domain servers 
    server unix:/tmp/example_1.sock fail_timeout=0; 
    server unix:/tmp/example_2.sock fail_timeout=0; 
    server unix:/tmp/example_3.sock fail_timeout=0; 
    server unix:/tmp/example_4.sock fail_timeout=0; 
  } 
 
  server { 
    listen 80; 
    client_max_body_size 4G; 
 
    server example.com; 
 
    location / { 
      proxy_set_header Host $http_host; 
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
      proxy_redirect off; 
      proxy_buffering off; 
      proxy_pass http://aiohttp; 
    } 
  } 
 
} 

它看起来是正确的。 server指令在 http理所当然。而 http 是父指令。我做错了什么?

请您参考如下方法:

我假设你有 http在你的/etc/nginx/nginx.conf 文件中,然后告诉 nginx 到 include sites-enabled/*;
那么你有

 http 
    http 
       server 

由于 http 指令应该只发生一次,只需从启用站点的配置文件中删除 http 指令