Some aliasdomains that point to a subdirectory function correctly while others do not

Discussion in 'Installation/Configuration' started by cbj4074, Sep 9, 2013.

  1. cbj4074

    cbj4074 Member

    Hello,

    I have several alias-domains that I would like to point to a specific location (subdirectory) within the parent domain.

    My intention (what should happen):

    Code:
    example1.com -> http://www.example.com/about-company/company-operations/
    www.example1.com -> http://www.example.com/about-company/company-operations/
    
    example1.net -> http://www.example.com/about-company/company-operations/
    www.example1.net -> http://www.example.com/about-company/company-operations/
    
    example2.com -> http://www.example.com/about-company/company-operations/
    www.example2.com -> http://www.example.com/about-company/company-operations/
    
    example2.net -> http://www.example.com/about-company/company-operations/
    www.example2.net -> http://www.example.com/about-company/company-operations/
    
    Actual result (what does happen):

    Code:
    example1.com -> http://www.example.com/
    www.example1.com -> http://www.example.com/about-company/company-operations/
    
    example1.net -> http://www.example.com/about-company/company-operations/
    www.example1.net -> http://www.example.com/
    
    example2.com -> http://www.example.com/
    www.example2.com -> http://www.example.com/
    
    example2.net -> http://www.example.com/
    www.example2.net -> http://www.example.com/
    
    All four aliasdomains are configured within ISPConfig the exact same way:

    Code:
    Aliasdomain: example1.com
    Parent Website: example.com
    Redirect Type: permanent
    Redirect Path: /about-company/company-operations/
    Auto-Subdomain: *.
    SEO Redirect: [none]
    Active: [checked]
    
    Aliasdomain: example1.net
    Parent Website: example.com
    Redirect Type: permanent
    Redirect Path: /about-company/company-operations/
    Auto-Subdomain: *.
    SEO Redirect: [none]
    Active: [checked]
    
    Aliasdomain: example2.com
    Parent Website: example.com
    Redirect Type: permanent
    Redirect Path: /about-company/company-operations/
    Auto-Subdomain: *.
    SEO Redirect: [none]
    Active: [checked]
    
    Aliasdomain: example2.net
    Parent Website: example.com
    Redirect Type: permanent
    Redirect Path: /about-company/company-operations/
    Auto-Subdomain: *.
    SEO Redirect: [none]
    Active: [checked]
    
    It is strange that the redirect functions as I expect for www.example1.com and example1.net, but not the other domains. I fail to see any logic or meaningful pattern that explains this behavior.

    Here is the full vhost configuration (nginx):

    Code:
    server {
            listen *:80;
    
    
            server_name example.com *.example.com *.example3.com example3.com *.example1.com example1.com *.example1.net example1.net *.example2.com example2.com *.example2.net example2.net *.example3.net example3.net;
    
            root   /var/www/example.com/web;
    
            if ($http_host != "www.example.com") {
                rewrite ^ $scheme://www.example.com$request_uri? permanent;
            }
            if ($http_host ~* "^(example1\.com|.+\.example1\.com)$") {
                rewrite ^(?!/\b(about-company/company-operations|stats)\b)/(.*)$ /about-company/company-operations/$2 permanent;
            }
            if ($http_host ~* "^(example1\.net|.+\.example1\.net)$") {
                rewrite ^(?!/\b(about-company/company-operations|stats)\b)/(.*)$ /about-company/company-operations/$2 permanent;
            }
            if ($http_host ~* "^(example2\.com|.+\.example2\.com)$") {
                rewrite ^(?!/\b(about-company/company-operations|stats)\b)/(.*)$ /about-company/company-operations/$2 permanent;
            }
            if ($http_host ~* "^(example2\.net|.+\.example2\.net)$") {
                rewrite ^(?!/\b(about-company/company-operations|stats)\b)/(.*)$ /about-company/company-operations/$2 permanent;
            }
    
    
            index index.html index.htm index.php index.cgi index.pl index.xhtml;
    
    
    
            error_log /var/log/ispconfig/httpd/example.com/error.log;
            access_log /var/log/ispconfig/httpd/example.com/access.log combined;
    
            ## Disable .htaccess and other hidden files
            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/client6/web9/web/stats/.htpasswd_stats;
            }
    
            location ^~ /awstats-icon {
                alias /usr/share/awstats/icon;
            }
    
            location ~ \.php$ {
                try_files /e7a252771309f4c05dfc8fa8ffa4a50a.htm @php;
            }
    
            location @php {
                try_files $uri =404;
                include /etc/nginx/fastcgi_params;
                fastcgi_pass 127.0.0.1:9018;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                #fastcgi_param PATH_INFO $fastcgi_script_name;
                fastcgi_intercept_errors on;
            }
    
    
            location / {
               try_files $uri $uri/ @virtual;
            }
    
            location @virtual {
                if ($uri !~ '/$') {
                   return 301 $uri/$is_args$args;
                }
                include /etc/nginx/fastcgi_params;
                fastcgi_pass unix:/var/lib/php5-fpm/web9.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_intercept_errors on;
                rewrite  ^(.*)$  /index.php?q=$1  last;
            }
    
            include /etc/nginx/nginx-misc.conf;
            include /etc/nginx/cache_static.conf;
            include /etc/nginx/pma.conf;
            include /etc/nginx/roundcube.conf;
    
    
    
    }
    
    Please note that I have changed the actual domain names to example.com, example1.com, etc. I mention this in the event that alphabetical order is somehow relevant to this problem.

    My ISPConfig version is 3.0.5.2.

    Thank you for any hints here.

    ETA:

    Interestingly enough, after some period of time (a couple of hours), none of the aliasdomains are redirecting to the specified URL/subdirectory; they are all redirecting to the top-level domain root. I realize that ISPConfig requires up to 60 seconds to write each change to disk, but I tested this at least 15 minutes after making my final change.

    In any case, it is possible that the rewrite rules for the aliasdomains should actually come before the SEO-redirect rules for the parent domain? If nginx processes these rules in the order in which the rules appear, it makes sense that the first rule

    Code:
            if ($http_host != "www.example.com") {
                rewrite ^ $scheme://www.example.com$request_uri? permanent;
            }
    
    is being triggered before any of the aliasdomain rules are even considered.

    Is there a specific reason for which ISPConfig places the aliasdomain rules after the SEO-redirect rules for the parent domain?
     
    Last edited: Sep 9, 2013
  2. cbj4074

    cbj4074 Member

    Never mind; ISPConfig is behaving properly, and operator error is at play.

    All I had to do to fix the issue was include the http://example.com prefix in the "Redirect Path" field for each aliasdomain.

    Making this change occurred to me because I noticed that ISPConfig creates different nginx configuration directives depending on whether or not the protocol and domain are included in the "Redirect Path". When protocol and domain are not included, ISPConfig creates the rewrite rules within the primary domain's "server {}" block, whereas when protocol and domain are included, ISPConfig creates each of the rewrites rules in its own server block, which is what "fixed" this issue for me.

    For what it's worth, I again noticed that it took up to 15 minutes or so for my changes to become effective. This leads me to believe that nginx (and not ISPConfig) is causing the delay. Maybe nginx caches its configuration, or its graceful "reload" can take quite some time to become effective.

    In any case, all is well!
     
    Last edited: Sep 9, 2013
  3. till

    till Super Moderator Staff Member ISPConfig Developer

    If you take a look in the ispconfig monitor > jobqueue. As long as a job is listed there, the configuration is not written to disk.
     

Share This Page