Question

Nginx container returning an error with Exit code 1 [emerg] 1#1: unknown directive "enable" in /etc/nginx/nginx.conf:45

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. The whole codes are the same so I am so confused why it is not working as the other.

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 (the left one server is my droplet, the right one is my other server) my droplet is not listening to 80 port normally it should listen as the other server.

my other server:

root@cihatserver:/home/cihat/app# netstat -plant | grep 80

output is: tcp6 0 0 :::80 :::* LISTEN 15696/docker-proxy

my droplet :

root@knowin-project-dev:/home/cihat/app# netstat -plant | grep 80

output is: –empty–

This is my Nginx log.

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

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


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
June 15, 2021
Accepted Answer

Hi there,

The error reports that the enable directive on line 45 is causing the problem but that line is commented out. The possible problem would be if you are using an old image that has the enable directive still not commented out.

I could suggest trying to rebuild the image and run the container again. I’ve just tested this with the Nginx config file that you’ve shared and the Dockerfile and it worked as expected.

Let me know how it goes. Regards, Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.