Question

Not able to start NGINX services, unknown directive "<!DOCTYPE" in /etc/nginx/sites-enabled/site1:6

I installed the NGINX and configured it was working. Later if wanted to change the /etc/hosts , /etc/hostconf & hostname. It was wrong from my part changing after the configuration has been completedm, i relasied this issue but latter. I was able to restore the infromation about etc/hosts , hostname etc but the servies of nginx is not starting up.

root@ip-172-31-21-204:~# nginx -t
nginx: [emerg] unknown directive "<!DOCTYPE" in /etc/nginx/sites-enabled/site1:6
nginx: configuration file /etc/nginx/nginx.conf test failed
journalctl -xe

Feb 27 20:43:13 ip-172-31-21-204 dhclient[556]: XMT: Solicit on ens5, interval 109320ms.
Feb 27 20:45:03 ip-172-31-21-204 dhclient[556]: XMT: Solicit on ens5, interval 121150ms.
Feb 27 20:46:19 ip-172-31-21-204 sshd[2345]: Invalid user user from 92.255.85.237 port 61852
Feb 27 20:46:19 ip-172-31-21-204 sshd[2345]: Received disconnect from 92.255.85.237 port 61852:11: Bye Bye [preauth]
Feb 27 20:46:19 ip-172-31-21-204 sshd[2345]: Disconnected from invalid user user 92.255.85.237 port 61852 [preauth]
Feb 27 20:47:04 ip-172-31-21-204 dhclient[556]: XMT: Solicit on ens5, interval 119330ms.
Feb 27 20:49:03 ip-172-31-21-204 dhclient[556]: XMT: Solicit on ens5, interval 124670ms.
Feb 27 20:51:08 ip-172-31-21-204 dhclient[556]: XMT: Solicit on ens5, interval 126880ms.
Feb 27 20:51:55 ip-172-31-21-204 dhclient[480]: DHCPREQUEST for 172.31.21.204 on ens5 to 172.31.16.1 port 67
Feb 27 20:51:55 ip-172-31-21-204 dhclient[480]: DHCPACK of 172.31.21.204 from 172.31.16.1
Feb 27 20:51:55 ip-172-31-21-204 dhclient[480]: bound to 172.31.21.204 -- renewal in 1635 seconds.
Feb 27 20:53:15 ip-172-31-21-204 dhclient[556]: XMT: Solicit on ens5, interval 110250ms.
Feb 27 20:55:05 ip-172-31-21-204 dhclient[556]: XMT: Solicit on ens5, interval 116830ms.
Feb 27 20:57:02 ip-172-31-21-204 dhclient[556]: XMT: Solicit on ens5, interval 111480ms.
Feb 27 20:57:19 ip-172-31-21-204 kernel: [UFW BLOCK] IN=ens5 OUT= MAC=02:36:35:9d:52:f8:02:31:52:19:17:48:08:00 SRC=162.142.125.176 DST=172.31.21.204 LEN=44
root@ip-172-31-21-204:~# systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sun 2022-02-27 20:32:05 UTC; 18min ago
     Docs: man:nginx(8)
  Process: 2263 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)

Feb 27 20:32:05 ip-172-31-21-204 systemd[1]: Starting A high performance web server and a reverse proxy server...
Feb 27 20:32:05 ip-172-31-21-204 nginx[2263]: nginx: [emerg] unknown directive "<!DOCTYPE" in /etc/nginx/sites-enabled/site1:6
Feb 27 20:32:05 ip-172-31-21-204 nginx[2263]: nginx: configuration file /etc/nginx/nginx.conf test failed
Feb 27 20:32:05 ip-172-31-21-204 systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Feb 27 20:32:05 ip-172-31-21-204 systemd[1]: nginx.service: Failed with result 'exit-code'.
Feb 27 20:32:05 ip-172-31-21-204 systemd[1]: Failed to start A high performance web server and a reverse proxy server.
root@ip-172-31-21-204:~# cat /etc/nginx/sites-enabled/site1
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

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
July 5, 2022

Hi there,

Your HTML code should not be added to the Nginx configuration file.

In the Nginx config file you should only have the following:

server {
  listen 80 default_server; 

  server_name .yourdomain.com;

  root /var/www/html;

  index index.php index.html index.htm;

}

Then in the /var/www/html directory you need to create a file called index.html and in that file add your HTML code.

Let me know if you have any questions!

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
Get started for free

Enter your email to get $200 in credit for your first 60 days with DigitalOcean.

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