0

I am trying to set up an nginx install on a Amazon Lightsail VPS running Debian (not the Nginx Bitnami package). I'm a bit of a newbie at this. I'm totally puzzled by what is happening.

Output of ls -l /etc/nginx/sites-enabled:

lrwxrwxrwx 1 root root 39 Jul 27 16:39 static -> /etc/nginx/sites-available/static

Contents of /etc/nginx/sites-available/static:

server {
    listen 80;
    listen [::]:80;
    server_name  'DOMAIN NAME' www.'DOMAIN NAME' www1.'DOMAIN NAME' 'IP ADDRESS OF SERVER'

    root /var/www/static
    index index.html;

    location / {
        index index.html;
        try_files $uri $uri/ =404;
    }
}

In the above, DOMAIN_NAME and IP ADDRESS are placeholders for the real text.

Output of nginx -T shows the contents of static displayed after the contents of /etc/nginx/nginx.conf. There are no server-name lines in this output except what's in static.

/var/log/nginx/access.log shows accesses when I enter the main domain name, but not the subdomain names. In any case, whether I enter the subdomain or just the main domain, I am shown the welcome page.

What's even more mystifying is that the welcome page seems to be at /var/www/html/index.html. So I modified that file too as a test. But the modified version wasn't displayed either.

I'm at my wit's end. What have I done wrong?

5
  • Try looking within /var/www/static instead of /var/www/html
    – Ramhound
    Commented Jul 27, 2021 at 17:17
  • Is each statement terminated with a ;? Your example shows some missing ;s. Commented Jul 27, 2021 at 19:38
  • @Ramhound it's not displaying the index.html in /var/www/static - that's the problem at present.
    – ShankarG
    Commented Jul 28, 2021 at 3:31
  • @RichardSmith I'll check this!
    – ShankarG
    Commented Jul 28, 2021 at 3:32
  • @RichardSmith you were right, that fixed it!
    – ShankarG
    Commented Jul 28, 2021 at 3:33

1 Answer 1

1

The comment from @RichardSmith on the question pointed me to the right answer.

I'd used code from other websites to construct my server block file (/etc/nginx/sites-available/static). But some of that code was wrong - it did not terminate every line with a ;.

Once I added that to the file, like so:

server {
    listen 80;
    listen [::]:80;
    server_name  'DOMAIN NAME' www.'DOMAIN NAME' www1.'DOMAIN NAME' 'IP ADDRESS OF SERVER';

    root /var/www/static;
    index index.html;

    location / {
        index index.html;
        try_files $uri $uri/ =404;
    }
}

It worked perfectly!

NB: Wish nginx -t would have given me a warning about this though...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .