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

后端 未结 4 1579
旧时难觅i
旧时难觅i 2020-12-15 03:01

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 Ngi

相关标签:
4条回答
  • 2020-12-15 03:36

    You may insert a part which should be inside http{} section into your nginx.conf and in /etc/nginx/sites-available/default leave just server{} section.

    0 讨论(0)
  • 2020-12-15 03:46

    I've been having similar issue. I needed to include upstream directive but I could't touch the /etc/nginx/nginx.conf file where the http directive is defined. The only thing I could do was to replace /etc/nginx/conf.d/default.conf (cloud/kubernetes automation stuff...)

    The solution is quite simple but since it might not be obvious (wasn't to me), here is how you can write your /etc/nginx/conf.d/default.conf file if you need to include upstream spec. (upstream and server directives are not enclosed by anything in this file)

    /etc/nginx/conf.d/default.conf

    upstream api {
        server ...;
    }
    
    server {
        listen              80;
        server_name         example.com;
        ...
    
        location / {
            proxy_pass      http://api;
            ...
        }
    }
    
    0 讨论(0)
  • 2020-12-15 03:51

    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)

    0 讨论(0)
  • 2020-12-15 03:54

    So, actually the problem was in the second server keyword. I used an example from aiohttp docs, and looks like they mistyped with "server example.com" instead of server_name example.com.

    0 讨论(0)
提交回复
热议问题