Zum Inhalt springen

Configure default server in ISPConfig with NginX

In the default configuration under ISPConfig there is no „default_server“ defined and in this case NginX grabs the first customer host and delivers this content by default. This can be problematic in several cases, especially with search engines.

To solve this issue you have to edit the configuration file under /etc/nginx/sites-enabled/default and change several lines. We distinguish between two different scenarios:

No IP addresses in the configuration of the website in ISPConfig

In this case it is sufficient to define a single „default_server“ block in the configuration file under /etc/nginx/sites-enabled/default:

# server block for http
server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name_in_redirect off;
    server_name _;
    return 301 <insert url here>;
}

# server block for https
server {
    listen 443 http2 default_server;
    listen [::]:443 http2 default_server;
    ssl_protocols TLSv1.3 TLSv1.2;
    ssl_certificate <full path to ssl certificate>;
    ssl_certificate_key <full path to ssl key>;
    server_name_in_redirect off;
    server_name _;
    return 301 <insert url here>;
}

IP addresses in the configuration of the website in ISPConfig

In this case we have to define a „default_server“ block in the configuration file under /etc/nginx/sites-enabled/default like above for every ip address.

# server block for http
server {
    listen <my_ipv4_address>:80 default_server;
    listen [<my_ipv6_address>]:80 default_server;
    server_name_in_redirect off;
    server_name _;
    return 301 <insert url here>;
}

# server block for https
server {
    listen <my_ipv4_address>:443 http2 default_server;
    listen [<my_ipv6_address>]:443 http2 default_server;
    ssl_protocols TLSv1.3 TLSv1.2;
    ssl_certificate <full path to ssl certificate>;
    ssl_certificate_key <full path to ssl key>;
    server_name_in_redirect off;
    server_name _;
    return 301 <insert url here>;
}

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert