Domanda

I have a wildcard DNS entry so *.mydomain.tld is directed to my server. I'm Using nginx I have 2 conf files titled:

  • default
  • myconf.conf

My conf files look like this:

default:

server {
    listen 80;
    listen [::]:80 default_server ipv6only=on;

    root /var/www/website;
    index index.html index.htm;

    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ /index.html;
    }
}

myconf.conf:

server {
    listen 80; 
    #listen [::]:80 default_server ipv6only=on;

    root /home/me/www/website;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    # orig # server_name localhost;
    server_name me.mydomain.tld;

    access_log /home/me/logs/me.mydomain.tld.access.log;
    error_log /home/me/logs/me.mydomain.tld.error.log warn;

    location / { 
        try_files $uri $uri/ $uri.php?$args;
    }   
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;

        # With php5-fpm:
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

When I browse to the domains as follows, these are the conf files that load up.

  • me.mydomain.tld loads up root directory defined in myconf.conf
  • mydomain.tld loads up root directory defined in default
  • anything.mydomain.tld loads up root directory defined in myconf.conf

What is going wrong that default is not being the catchall it should be? anything.mydomain.tld should be loading the root directory in the default conf file.

È stato utile?

Soluzione

In your default config file, you have to specify default_server on both listen lines; also, you need to remove the server_name line:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /var/www/website;
    index index.html index.htm;

    #server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ /index.html;
    }
}

The underscore that you are using for the server_name is not actually a wild card (if that was your intent). From the nginx Server Names documentation:

There is nothing special about this name, it is just one of a myriad of invalid domain names which never intersect with any real name. Other invalid names like “--” and “!@#” may equally be used.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top