63

I have the following nginx config, e.g.

server {
        listen   80;
        server_name example.com
        allow 127.0.0.0/8;

When I restart, it warn me:

Restarting nginx: nginx: [warn] server name "127.0.0.0/8" has suspicious 
symbols in /etc/nginx/sites-enabled/xxx

Any idea?

Ryan
  • 5,341
  • 21
  • 71
  • 87

4 Answers4

141

I guess you are missing the ; at the end of the server_name directive so it interprets the allow line as part of the server name.

server {
        listen   80;
        server_name example.com;
        allow 127.0.0.0/8;
Sven
  • 97,248
  • 13
  • 177
  • 225
  • 5
    I have been here before... I was just about to upvote your answer then I realized I already did! Thanks for a second time :-) – codenamejames Aug 31 '17 at 17:01
  • Thank you. I was missing the `;` at the end, and it was causing `404 Not Found nginx` in my browser and `server name "/var/www/mysite" has suspicious symbols in /etc/nginx/sites-available/mysite.conf:8` in my `/var/log/nginx/error.log`. – Ryan Apr 26 '19 at 11:34
  • Saved a life. I guess overlooked it because nginx doesn't see it as invalid syntax. – Peter Chaula Jan 18 '21 at 12:59
  • Typo'ing in a ':' rather a ';' will warn this as well. – CNSKnight Oct 20 '21 at 15:43
8

For me the cause of this error was having 'http://' in the server_name.

i.e. I changed this:

server {
    listen <Server name>:80;
    server_name <DNS name> http://localhost:28080;
    ...

To this:

server {
    listen <Server name>:80;
    server_name <DNS name> localhost:28080;
    ...
Gut Feeling
  • 91
  • 1
  • 4
2

A simple directive consists of the name and parameters separated by spaces and ends with a semicolon (;).

In your case server_name example.com semicolon (;) is missing.

server {
        listen   80;
        server_name example.com;
        allow 127.0.0.0/8;
Nanhe Kumar
  • 409
  • 4
  • 6
-1

In my case error was in website url

server_name  http://testapp.com;

so I modified it this way

server_name  testapp.com;

and when I tried

sudo nginx -t Outputnginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful

it worked for me