nginx default domain

Discussion in 'ISPConfig 3 Priority Support' started by arraken, Apr 4, 2014.

  1. arraken

    arraken Member

    Hi!

    When I visit a domain that points to my webserver, but has no website created in ISPConfig, I get redirected to a site that belongs to a client.

    I found some posts about apache which explained that apache automatically redirects to the first vhost in alphabetical order. How does this work in nginx? I tried to create a 000-default.tld vhost, but I still get redirected to the customers website.
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    It should be the same in nginx. Create a new website in ispconfig with the name:

    000default.tld

    to catch the requests. this website must use the same IP settings. e.g. when all your sites use a IP and not *, then the default site must use a IP as well. as IP addresses are a stronger match then wildcards.
     
  3. arraken

    arraken Member

    Ok, it partially works. All my websites use * as ipv4 address. When i use * in my 000default.tld website, I still get redirected to the client's website strangely.

    But when i manually edit the vhost file, and change *:80 to "1.2.3.4:80", it works. However, i cant choose the IP-address in the ispconfig-interface, only *. So my manual changes in the vhost-file will be overwritten. How can i solve this?
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    Add the IP under System > server IP. Then you will be able to choose it in the website settings.
     
  5. arraken

    arraken Member

    well, that didn't really work: when I choose the IP in my 000default.tld domain, every domain on my server suddenly pointed to this domain. I quickly selected the IP instead of * for every website on my server. Now it's back to where I started: every domain that points to my server, but doesn't have a website points to the clients website again. So the 000default.tld again doesn't have top priority.
     
  6. arraken

    arraken Member

    I have still been unable to solve this problem. I also found out that when I type the IP address of my webserver into the browser, i also get redirected to the client's domain.

    Here is the vhost file. Maybe the problem lies here?

    Code:
    server {
            listen 1.2.3.4:80;
    
    
            server_name clientdomain.tld www.clientdomain.tld;
    
            root   /var/www/clientdomain.tld/web;
    
            if ($http_host = "clientdomain.tld") {
                rewrite ^ $scheme://www.clientdomain.tld$request_uri? permanent;
            }
    
    
            index index.html index.htm index.php index.cgi index.pl index.xhtml;
    
    
    
            error_page 400 /error/400.html;
            error_page 401 /error/401.html;
            error_page 403 /error/403.html;
            error_page 404 /error/404.html;
            error_page 405 /error/405.html;
            error_page 500 /error/500.html;
            error_page 502 /error/502.html;
            error_page 503 /error/503.html;
            recursive_error_pages on;
            loctldion = /error/400.html {
    
                internal;
            }
            loctldion = /error/401.html {
    
                internal;
            }
            loctldion = /error/403.html {
    
                internal;
            }
            loctldion = /error/404.html {
    
                internal;
            }
            loctldion = /error/405.html {
    
                internal;
            }
            loctldion = /error/500.html {
    
                internal;
            }
            loctldion = /error/502.html {
    
                internal;
            }
            loctldion = /error/503.html {
    
                internal;
            }
    
            error_log /var/log/ispconfig/httpd/clientdomain.tld/error.log;
            access_log /var/log/ispconfig/httpd/clientdomain.tld/access.log combined;
    
            loctldion ~ /\. {
                deny all;
                access_log off;
                log_not_found off;
            }
    
            loctldion = /favicon.ico {
                log_not_found off;
                access_log off;
            }
    
            loctldion = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
            }
    
            loctldion /sttlds {
    
                index index.html index.php;
                auth_basic "Members Only";
                auth_basic_user_file /var/www/clients/client6/web6/web/sttlds/.htpasswd_sttlds;
            }
    
            loctldion ^~ /awsttlds-icon {
                alias /usr/share/awsttlds/icon;
            }
    
            loctldion ~ \.php$ {
                try_files /c4e2a8245934966216a8f013c75a01fe.htm @php;
            }
    
            loctldion @php {
                try_files $uri =404;
                include /etc/nginx/fastcgi_params;
                fastcgi_pass 127.0.0.1:9015;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            }
    
    
    
    
            loctldion / {
                            try_files $uri $uri/ /index.php?$args;
            }
    
                   rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    
            loctldion ~* \.(jpg|jpeg|png|gif|css|js|ico)$ {
                            expires max;
                            log_not_found off;
            }
    
    
    }
    
    server {
            listen 1.2.3.4:80;
    
    
            server_name aliasdomain.tld;
            if ($http_host = "aliasdomain.tld") {
                rewrite ^ $scheme://www.aliasdomain.tld$request_uri? permanent;
            }
            rewrite ^ http://www.clientdomain.tld$request_uri? redirect;
    }
    server {
            listen 1.2.3.4:80;
    
    
            server_name www.aliasdomain.tld;
            rewrite ^ http://www.clientdomain.tld$request_uri? redirect;
    }
     
    Last edited: Apr 11, 2014
  7. falko

    falko Super Moderator Howtoforge Staff

    Can you post the contents of the 000default.tld file?
     
  8. arraken

    arraken Member

    contents of 000default.tld.vhost

    Code:
    server {
            listen 1.2.3.4:80;
    
    
            server_name 000default.at www.000default.at;
    
            root   /var/www/000default.at/web;
    
    
    
            index index.html index.htm index.php index.cgi index.pl index.xhtml;
    
    
    
            error_page 400 /error/400.html;
            error_page 401 /error/401.html;
            error_page 403 /error/403.html;
            error_page 404 /error/404.html;
            error_page 405 /error/405.html;
            error_page 500 /error/500.html;
            error_page 502 /error/502.html;
            error_page 503 /error/503.html;
            recursive_error_pages on;
            location = /error/400.html {
    
                internal;
            }
            location = /error/401.html {
    
                internal;
            }
            location = /error/403.html {
    
                internal;
            }
            location = /error/404.html {
    
                internal;
            }
            location = /error/405.html {
    
                internal;
            }
            location = /error/500.html {
    
                internal;
            }
            location = /error/502.html {
    
                internal;
            }
            location = /error/503.html {
    
                internal;
            }
    
            error_log /var/log/ispconfig/httpd/000default.at/error.log;
            access_log /var/log/ispconfig/httpd/000default.at/access.log combined;
    
            location ~ /\. {
                deny all;
                access_log off;
                log_not_found off;
            }
    
            location = /favicon.ico {
                log_not_found off;
                access_log off;
            }
    
            location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
            }
    
            location /stats {
    
                index index.html index.php;
                auth_basic "Members Only";
                auth_basic_user_file /var/www/clients/client5/web18/web/stats/.htpasswd_stats;
            }
    
            location ^~ /awstats-icon {
                alias /usr/share/awstats/icon;
            }
    
            location ~ \.php$ {
                try_files /f3802e15d4c11e50a65be9f19ccf6b3a.htm @php;
            }
    
            location @php {
                try_files $uri =404;
                include /etc/nginx/fastcgi_params;
                fastcgi_pass 127.0.0.1:9027;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            }
    
    
    
    
    
    
    
    }
     
  9. falko

    falko Super Moderator Howtoforge Staff

    This looks lie a vhost created by ISPConfig. Was there no default vhost coming with nginx when you installed it?
     
  10. arraken

    arraken Member

    Hi!

    Yes, I created the 000default website in ISPConfig - this is the vhost for it. I thought that is the way to do it.

    I also have a default vhost of nginx. The file ist just called "default". Should I just rename this file to 000default, and delete the website I created in ISPConfig?

    This is the content of the default nginx file:

    Code:
    # You may add here your
    # server {
    #       ...
    # }
    # statements for each of your virtual hosts to this file
    
    ##
    # You should look at the following URL's in order to grasp a solid understanding
    # of Nginx configuration files in order to fully unleash the power of Nginx.
    # http://wiki.nginx.org/Pitfalls
    # http://wiki.nginx.org/QuickStart
    # http://wiki.nginx.org/Configuration
    #
    # Generally, you will want to move this file somewhere, and start with a clean
    # file but keep this around for reference. Or just disable in sites-enabled.
    #
    # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
    ##
    
    server {
            #listen   80; ## listen for ipv4; this line is default and implied
            #listen   [::]:80 default ipv6only=on; ## listen for ipv6
    
            root /usr/share/nginx/www;
            index index.html index.htm;
    
            # Make site accessible from http://localhost/
            server_name localhost;
    
            location / {
                    # First attempt to serve request as file, then
                    # as directory, then fall back to index.html
                    try_files $uri $uri/ /index.html;
                    # Uncomment to enable naxsi on this location
                    # include /etc/nginx/naxsi.rules
            }
    
            location /doc/ {
                    alias /usr/share/doc/;
                    autoindex on;
                    allow 127.0.0.1;
                    deny all;
            }
    
            # Only for nginx-naxsi : process denied requests
            #location /RequestDenied {
                    # For example, return an error code
                    #return 418;
            #}
    
            #error_page 404 /404.html;
    
            # redirect server error pages to the static page /50x.html
            #
            #error_page 500 502 503 504 /50x.html;
            #location = /50x.html {
            #       root /usr/share/nginx/www;
            #}
    
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            #location ~ \.php$ {
            #       fastcgi_split_path_info ^(.+\.php)(/.+)$;
            #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
            #
            #       # With php5-cgi alone:
            #       fastcgi_pass 127.0.0.1:9000;
            #       # With php5-fpm:
            #       fastcgi_pass unix:/var/run/php5-fpm.sock;
            #       fastcgi_index index.php;
            #       include fastcgi_params;
            #}
    
            # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            #location ~ /\.ht {
            #       deny all;
            #}
    }
    
    
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #       listen 8000;
    #       listen somename:8080;
    #       server_name somename alias another.alias;
    #       root html;
    #       index index.html index.htm;
    #
    #       location / {
    #               try_files $uri $uri/ /index.html;
    #       }
    #}
    
    
    # HTTPS server
    #
    #server {
    #       listen 443;
    #       server_name localhost;
    #
    #       root html;
    #       index index.html index.htm;
    #
    #       ssl on;
    #       ssl_certificate cert.pem;
    #       ssl_certificate_key cert.key;
    #
    #       ssl_session_timeout 5m;
    #
    #       ssl_protocols SSLv3 TLSv1;
    #       ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
    #       ssl_prefer_server_ciphers on;
    #
    #       location / {
    #               try_files $uri $uri/ /index.html;
    #       }
    #}
    
    
     
  11. drewb0y

    drewb0y Member

    Was this issue resolved successfully? I have a similar situation on my server. All the sites are selected to point to an IP address. BUt going to the IP address pulls up a client site rather than the default index.html.

    in /etc/nginx/sites-enabled/ I have a symlink from

    Code:
    [B]default[/B] -> /etc/nginx/sites-available/default
    Should I be able to create a symlink from 000default.tld.vhost to /etc/nginx/sites-available/default

    Unfortunately I can't remember how it worked before I started adding domains to it.

    This is on a fresh install following the tutorial with nginx on debian wheezy.

    Thanks in advance for any tips.
     
  12. drewb0y

    drewb0y Member

    Also I noticed in my /etc/nginx/sites-enabled/ directory the links are named such as

    Code:
    000-apps.vhost
    000-ispconfig.vhost
    so should
    Code:
    000default.tld.vhost
    show up as
    Code:
    000-default.tld.vhost
    ?
     
  13. till

    till Super Moderator Staff Member ISPConfig Developer

    Thats ok as it is.
     
  14. arraken

    arraken Member

    Hi!

    I resolved this by just manually creating a symlink in /etc/nginx/sites-enabled that points to my default vhost, like so:

    Code:
    ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/000-default
    My default file looks like this:

    Code:
    server {
            listen 1.2.3.4:80;
            listen   [::]:80 default ipv6only=on; ## listen for ipv6
    
            root /usr/share/nginx/html;
            index index.html index.htm;
    
            # Make site accessible from http://localhost/
            server_name localhost;
    
            location / {
                    # First attempt to serve request as file, then
                    # as directory, then fall back to index.html
                    try_files $uri $uri/ /index.html;
                    # Uncomment to enable naxsi on this location
                    # include /etc/nginx/naxsi.rules
            }
    
            location /doc/ {
                    alias /usr/share/doc/;
                    autoindex on;
                    allow 127.0.0.1;
                    deny all;
            }
        }
    
    In my /usr/share/nginx/html/index.html I just put a welcome message.
     
  15. drewb0y

    drewb0y Member

    What's strange is that I have 2 IP addresses configured on my server.
    For the secondary IP, going to the IP address in the browser pulls up the default page as it should.

    I tried your symlink suggestion and after restarting I get the same result.
     

Share This Page