Question

Nginx server block redirection to web page incorrectly

Having followed the Nginx Ubuntu 20.04 setup tutorial Nginx appears to be serving the domain name (groove-genie.co.uk) but I’m unable to redirect to the web page of my application on port 8082 via https.

When I run Nginx -t I encounter the following messages:

nginx: [warn] conflicting server name "groove-genie.co.uk" on 0.0.0.0:443, ignored
nginx: [warn] conflicting server name "groove-genie.co.uk" on 0.0.0.0:80, ignored.

By all accounts it would appear that I have multiple server blocks configured; the challenge is my uncertainty around how I identify the offending lines of code which need to be removed from the Nginx conf files in order to rectify the problem.

I have attached the conf file in the hope someone can point me in the right direction as i’ve now gone “code-blind” after spending weeks trying to figure it out.

groove-genie.co.uk.conf

server {

        root /var/www/groove-genie.co.uk/html;
        index index.html index.htm index.nginx-debian.html;

        server_name groove-genie.co.uk www.groove-genie.co.uk;

        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/groove-genie.co.uk/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/groove-genie.co.uk/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.groove-genie.co.uk) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = groove-genie.co.uk) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80;
        listen [::]:80;

        server_name groove-genie.co.uk www.groove-genie.co.uk;
    return 404; # managed by Certbot




}

libretime.conf

server {
  listen 8082;
  listen [::]:8082;

  access_log /var/log/nginx/libretime.access.log;
  error_log /var/log/nginx/libretime.error.log;

  root /usr/share/libretime/legacy/public;

  index index.php index.html index.htm;

  client_max_body_size 512M;
  client_body_timeout 300s;

  location ~ \.php$ {
    fastcgi_buffers 64 4K;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    # try_files $uri =404;
    try_files $fastcgi_script_name =404;

    include fastcgi_params;

    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    set $path_info $fastcgi_path_info;
    fastcgi_param PATH_INFO $path_info;
    include fastcgi_params;

    fastcgi_index index.php;
    fastcgi_pass unix:/run/libretime-legacy.sock;
  }

  location / {
    try_files $uri $uri/ /index.php$is_args$args;
  }

  location ~ ^/api/(v2|browser) {
    include proxy_params;
    proxy_redirect off;
    proxy_pass http://unix:/run/libretime-api.sock;
  }
}
server {
    if ($host = groove-genie.co.uk) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    server_name groove-genie.co.uk;
    location / {
        rewrite ^ https://$server_name$request_uri? permanent;
    }


}
server {
    listen 443 ssl;
    server_name groove-genie.co.uk;
    ssl_certificate /etc/letsencrypt/live/groove-genie.co.uk/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/groove-genie.co.uk/privkey.pem; # managed by Certbot


    location / {
        proxy_set_header Host              $host;
        proxy_set_header X-Real-IP         $remote_addr;
        proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host  $host;
        proxy_set_header X-Forwarded-Port  $server_port;

        proxy_pass http://groove-genie.co.uk:8082/;
    }


}

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
April 26, 2023

Heya @6266fe4040594976a511ca0fa9b285,

From the provided configuration, it seems that there are multiple server blocks for the same domain name and port combination. To fix this, we will need to consolidate the server blocks in both configuration files.

groove-genie.co.uk.conf:

server {
    root /var/www/groove-genie.co.uk/html;
    index index.html index.htm index.nginx-debian.html;

    server_name groove-genie.co.uk www.groove-genie.co.uk;

    location / {
        proxy_set_header Host              $host;
        proxy_set_header X-Real-IP         $remote_addr;
        proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host  $host;
        proxy_set_header X-Forwarded-Port  $server_port;

        proxy_pass http://groove-genie.co.uk:8082/;
    }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/groove-genie.co.uk/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/groove-genie.co.uk/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.groove-genie.co.uk) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    if ($host = groove-genie.co.uk) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    listen [::]:80;

    server_name groove-genie.co.uk www.groove-genie.co.uk;
    return 404; # managed by Certbot
}

libretime.conf:

server {
  listen 8082;
  listen [::]:8082;

  access_log /var/log/nginx/libretime.access.log;
  error_log /var/log/nginx/libretime.error.log;

  root /usr/share/libretime/legacy/public;

  index index.php index.html index.htm;

  client_max_body_size 512M;
  client_body_timeout 300s;

  location ~ \.php$ {
    fastcgi_buffers 64 4K;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    # try_files $uri =404;
    try_files $fastcgi_script_name =404;

    include fastcgi_params;

    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    set $path_info $fastcgi_path_info;
    fastcgi_param PATH_INFO $path_info;
    include fastcgi_params;

    fastcgi_index index.php;
    fastcgi_pass unix:/run/libretime-legacy.sock;
  }

  location / {
    try_files $uri $uri/ /index.php$is_args$args;
  }

  location ~ ^/api/(v2|browser) {
    include proxy_params;
    proxy_redirect off;
    proxy_pass http://unix:/run/libretime-api.sock;
  }
}

Try DigitalOcean for free

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

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

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

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

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