Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

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

I'm new to NGINX and I'm trying to setup minimal working thing. So I trying to run aiohttp mini-app with nginx and supervisor (by this example). But I can't configure Nginx right and getting the following error:

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

Here is full default.conf file:

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;
    }
  }

}

It looks correct. server directive is in http as it should be. And http is parent directive. What I'm doing wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I am assuming that you have http in your /etc/nginx/nginx.conf file which then tells nginx to include sites-enabled/*;

So then you have

 http
    http
       server

As the http directive should only happen once just remove the http directive from your sites-enabled config file(s)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...