Home > other >  nginx: [emerg] "http" directive is not allowed here in /etc/nginx/conf.d/site.conf:1
nginx: [emerg] "http" directive is not allowed here in /etc/nginx/conf.d/site.conf:1

Time:07-19

I am trying to create a minimal nginx running locally on a node.js app.

I have the follwing configuration:

http{
  log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                               '$status $body_bytes_sent "$http_referer" '
                               '"$http_user_agent" "$http_x_forwarded_for"';

  access_log /var/log/nginx/access.log main;

  server {
    listen       80;
    server_name  app.dev www.app.dev;

    gzip on;
    gzip_disable "msie6";

    gzip_comp_level 6;
    gzip_min_length 1100;
    gzip_buffers 16 8k;
    gzip_proxied any;
    gzip_types
    text/plain
    text/css
    text/js
    text/xml
    text/javascript
    application/javascript
    application/x-javascript
    application/json
    application/xml
    application/rss xml
    image/svg xml;

    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-NginX-Proxy true;
    proxy_redirect off;

    location / {
      proxy_pass http://app:3000;
    }
  }
}

I have the app and nginx in a docker-compose, but when I do docker-compose up I am getting the following from the logs of nginx:

nginx: [emerg] "http" directive is not allowed here in /etc/nginx/conf.d/site.conf:1

Any idea of what I am doing wrong here?

CodePudding user response:

You already have http directive in /etc/nginx.conf so you can't define it again in a different file. Please put http directive config in /etc/nginx.conf and server directives config in /etc/nginx/conf.d/* . Also, you can put HTTP and server directives in /etc/nginx.conf too (all in one).

  • Related