linuxdockernginxserverserver-configuration

Nginx with Docker : nginx: [emerg] unknown directive "enable" in /etc/nginx/nginx.conf


I have 2 servers one is on the Digital ocean the other is somewhere else. I have one project and it is working well with all apps on that server. But, I wanted to create a droplet and move it to the digital ocean so I was copied all files to the new server(digital ocean) via sudo scp command. All services are working well except Nginx is returning Exit code 1 as below image. The whole codes are the same so I am so confused why it is not working as the other.

enter image description here

May I know what might I am missing?

it is my nginx.conf file :

worker_processes 4;
    
    events {
      worker_connections 4096;
    }
    
    http {
    
      server {
        listen 80 default_server;
        server_name "";
        return 444;
      }
    
      server {
        server_name game-dev.myappapp.com;
    
        location / {
          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_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
    
          proxy_pass http://game_nodes;
          proxy_redirect off;
        }
      }
      server {
        if ($host = game-dev.myappapp.com) {
          return 301 https://$host$request_uri;
        }
    
    
        listen 80;
        listen [::]:80;
        server_name game-dev.myappapp.com;
        return 404;
      }
    
      upstream game_nodes {
        # enable sticky session
        #ip_hash;
        server game-alpha:3000;
        keepalive 8;
      }
    
      server {
        server_name api-dev.myappapp.com;
    
        location / {
          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_pass http://main_nodes;
          proxy_redirect off;
    
        }
      }
    
      server {
        if ($host = api-dev.myappapp.com) {
          return 301 https://$host$request_uri;
        }
    
        listen 80;
        listen [::]:80;
        server_name api-dev.myappapp.com;
        return 404;
      }
    
      upstream main_nodes {
        server main-alpha:8000;
        server main-beta:8000;
        keepalive 8;
      }
    }

it is my Dockerfile :

FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf

As you can see from below screenshot (the left server is my droplet, the right one is my other server) my droplet is not listening to 80 port normally it should listen to 80 port the other server.

enter image description here

This is my Nginx log from DigitalOcean droplet.

root@knowin-project-dev:/home/cihat/app# docker logs nginx
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2021/06/13 20:22:46 [emerg] 1#1: unknown directive "enable" in /etc/nginx/nginx.conf:45
nginx: [emerg] unknown directive "enable" in /etc/nginx/nginx.conf:45

it is nginx.co.conf from DigitalOcean droplet:

    root@knowin-project-dev:/home/cihat/app# docker run -it nginx /bin/bash 
    root@1c54013ff2c8:/# cat etc/nginx/nginx.conf 
    user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    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;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

Note: ufw's status is inactive. So all ports are available.


Solution

  • Read the error message:

    2021/06/13 20:22:46 [emerg] 1#1: unknown directive "enable" in /etc/nginx/nginx.conf:45
    nginx: [emerg] unknown directive "enable" in /etc/nginx/nginx.conf:45
    

    You have an syntax error in your config file #45 The configuration file you have shared looks good on line 45 in genera as your "enable sticky session" is commented out with the # sign.

    Make sure the configuration file in your running container is the identically by typing

    docker exec nginx /bin/bash -c "cat /etc/nginx/nginx.conf" | tee nginx.co.conf

    on your digital ocean server. Please share the output of the nginx.co.conf file and make sure line 45 is commented out as well.

    How did you deployed the docker-container? Did you exported them as tar and uploaded them so the new server?? Sounds like you have some differences in between your local container and that one on digitial ocean.