Question

Nginx server block displaying wrong site on droplet

Posted September 12, 2020 308 views
Nginx

I have 3 sites on one droplet. The first two work fine, but as I add a third following this guide it directs itself to the first site I uploaded to the droplet. I’ve triple checked my symlinks between sites-enabled and sites-available, and the files themselves within (including having a www. and non www. listed in the server_name line), and I can’t understand why this would be happening when the second site never had this problem following the same method. I even restored a backup of my entire droplet and redid it, but the problem persists. Below are the two files under sites-available (the only difference being an SSL cert by certbot in the first site):

Original Site

server {
  listen 80;
  listen [::]:80;

  root /var/www/anchoridea.com/html;
  index index.html index.htm index.nginx-debian.html;

  server_name anchoridea.com www.anchoridea.com;

  location / {
    try_files $uri $uri/ =404;
  }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/anchoridea.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/anchoridea.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}
server {
    if ($host = www.anchoridea.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = anchoridea.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


  listen 80;
  listen [::]:80;

  server_name anchoridea.com www.anchoridea.com;
    return 404; # managed by Certbot




}

New Site

server {
    listen 80;
    listen [::]:80;
    root /var/www/prairiestormpaintball.com/html;
    index index.html index.htm index.nginx-debian.html;

    server_name prairiestormpaintball.com www.prairiestormpaintball.com;

    location / {
        try_files $uri $uri/ =404;
    }
}

Any help would be greatly appreciated, thanks!

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.

×
2 answers

Hi there @CanuckLuck,

I’ve seen the same behavior when the document root directory is not readable or writable by the Nginx user.

What I could suggest is making sure that your /var/www/prairiestormpaintball.com/html folder has the same permissions and ownership as the /var/www/anchoridea.com/html folder.

Also what I could suggest is checking your Nginx error log to see if there’s some more information about the problem:

  • tail -100 /var/log/nginx/error.log

Let me know how it goes!
Regards,
Bobby

  • Can you point me to a tutorial on checking/changing permissions? When I tried to check the error log I got

    tail: cannot open '/var/log/nginx/error.log' for reading: Permission denied
    

    So I’m guessing there’s some issue here with my non-root user. I did follow this page: https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-16-04 but I found the $USER:$USER part a bit confusing as to what it needs to be replaced with so I might have messed it up.

    by Justin Ellingwood
    When using the Nginx web server, server blocks (similar to the virtual hosts in Apache) can be used to encapsulate configuration details and host more than one domain off of a single server. In this guide, we'll discuss how to configure server blocks in Nginx on an Ubuntu...
    • Hi there @CanuckLuck,

      What I would usually do to get the Nginx user is to run the following command:

      • sudo ps -aux | grep -i nginx

      You would see an output like this:

      www-data    7651  0.0  0.5  68220  5200 ?        S    Sep13   0:00 nginx: worker process
      

      In my case, the user is www-data. This is the default user, so if you have not made any changes to your Nginx config, yours should be the same as well.

      Regarding the tail command, you can use sudo to get over the permissions error:

      • sudo tail -100 /var/log/nginx/error.log

      Let me know how it goes!
      Regards,
      Bobby

      • I got 3 lines from that first input (anchor is my non-root user)

        anchor  4032 0.0 0.0 14856 1100 ttyl  S+ 16:59 0:00 grep --color=auto -i nginx
        
        root  18278 0.0 0.0 142844 1676 ?  Ss Sep13 0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
        
        www-data 18281 0.0 0.4 145476 9648 ?  S Sep13 0:01 nginx: worker process
        

        and the error log says:

        [crit] 18281#18281: *972 SSL_do_handshake() failed (SSL: error:1420918C:SSL routines:tls_early_post_process_client_hello:version too low) while SSL handshaking, client: 198.143.155.138, server: 0.0.0.0:443
        

Hi @CanuckLuck

I have tried to access your domains prairiestormpaintball.com, www.prairiestormpaintball.com, anchoridea.com, and www.anchoridea.com. They all point to their own website. There is no redirection. Did you fixed your problem?

Submit an Answer