Question

how to handle it?

root@ubuntu-s-1vcpu-1gb-intel-sgp1-01:~# nginx -t -c /etc/nginx/nginx.conf
nginx: [emerg] unknown directive "        listen" in /etc/nginx/sites-enabled/dankerdan.my.id:2
nginx: configuration file /etc/nginx/nginx.conf test failed
root@ubuntu-s-1vcpu-1gb-intel-sgp1-01:~# sudo service nginx restart
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
root@ubuntu-s-1vcpu-1gb-intel-sgp1-01:~# nginx -t -c /etc/nginx/nginx.conf
nginx: [emerg] unknown directive "        listen" in /etc/nginx/sites-enabled/dankerdan.my.id:2
nginx: configuration file /etc/nginx/nginx.conf test failed
root@ubuntu-s-1vcpu-1gb-intel-sgp1-01:~# nginx -t
nginx: [emerg] unknown directive "        listen" in /etc/nginx/sites-enabled/dankerdan.my.id:2
nginx: configuration file /etc/nginx/nginx.conf test failed
root@ubuntu-s-1vcpu-1gb-intel-sgp1-01:~# sudo service nginx stop
root@ubuntu-s-1vcpu-1gb-intel-sgp1-01:~# sudo service nginx start
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
root@ubuntu-s-1vcpu-1gb-intel-sgp1-01:~# systemctl status nginx.service
● nginx.service - The nginx HTTP and reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Thu 2022-12-22 20:37:20 WIB; 17s ago
    Process: 52174 ExecStartPre=/opt/nginx/sbin/nginx -t (code=exited, status=203/EXEC)
Dec 22 20:37:20 ubuntu-s-1vcpu-1gb-intel-sgp1-01 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Dec 22 20:37:20 ubuntu-s-1vcpu-1gb-intel-sgp1-01 systemd[52174]: nginx.service: Failed to execute command: No such file or directoryDec 22 20:37:20 ubuntu-s-1vcpu-1gb-intel-sgp1-01 systemd[52174]: nginx.service: Failed at step EXEC spawning /opt/nginx/sbin/nginx:>Dec 22 20:37:20 ubuntu-s-1vcpu-1gb-intel-sgp1-01 systemd[1]: nginx.service: Control process exited, code=exited, status=203/EXEC
Dec 22 20:37:20 ubuntu-s-1vcpu-1gb-intel-sgp1-01 systemd[1]: nginx.service: Failed with result 'exit-code'.
Dec 22 20:37:20 ubuntu-s-1vcpu-1gb-intel-sgp1-01 systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
lines 1-11/11 (END)__****__

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.

KFSys
Site Moderator
Site Moderator badge
November 26, 2023

Heya,

The error messages you’re encountering indicate your listen directive is no in it’s proper place.

  1. Unknown Directive Error: The error nginx: [emerg] unknown directive "listen" suggests that there is a syntax error in your Nginx configuration file. This is often caused by incorrect indentation, missing semicolons, or other syntax issues.

To resolve these issues:

For the Syntax Error:

  1. Check Configuration Syntax: Open the /etc/nginx/sites-enabled/dankerdan.my.id file and check the syntax, especially around line 2 where the listen directive is. Ensure that it’s correctly formatted. For example:
server {
    listen 80;
    # ... other directives ...
}

Make sure there are no unwanted spaces or characters before the listen directive and that each directive ends with a semicolon (;).

  1. Check for Tab Characters: Sometimes, using tab characters instead of spaces can cause issues. Replace any tab characters with spaces and see if that resolves the issue.

  2. Validate the Configuration: After making changes, validate the configuration with nginx -t to ensure there are no syntax errors.

Bobby Iliev
Site Moderator
Site Moderator badge
December 23, 2022

Hi there,

As reported by the nginx -t command you have a syntax error in your /etc/nginx/sites-enabled/dankerdan.my.id file. You need to edit that fie and remove the listen directive from line two.

Feel free to share the complete /etc/nginx/sites-enabled/dankerdan.my.id file here so I could advise you on what exactly needs to be changed!

For more information on how Nginx server blocks work, I would recommend this tutorial here:

https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-16-04

Best,

Bobby

Try DigitalOcean for free

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

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel