Learn about Centmin Mod LEMP Stack today
Become a Member

acmetool.sh redirects www to non-www

Discussion in 'Add Ons' started by Jon Snow, Oct 12, 2017.

  1. Jon Snow

    Jon Snow Active Member

    593
    92
    28
    Jun 30, 2017
    Ratings:
    +147
    Local Time:
    11:12 PM
    Nginx 1.13.9
    MariaDB 10.1.31
    Code (Text):
    grep -rn 'domain.org' /usr/local/nginx/conf
    /usr/local/nginx/conf/ssl/domain.org/acme-vhost-config.txt:1:  ssl_dhparam /usr/local/nginx/conf/ssl/domain.org/dhparam.pem;
    /usr/local/nginx/conf/ssl/domain.org/acme-vhost-config.txt:2:  ssl_certificate      /usr/local/nginx/conf/ssl/domain.org/domain.org-acme.cer;
    /usr/local/nginx/conf/ssl/domain.org/acme-vhost-config.txt:3:  ssl_certificate_key  /usr/local/nginx/conf/ssl/domain.org/domain.org-acme.key;
    /usr/local/nginx/conf/ssl/domain.org/acme-vhost-config.txt:4:  ssl_trusted_certificate /usr/local/nginx/conf/ssl/domain.org/domain.org-acme.cer;
    /usr/local/nginx/conf/ssl/domain.org/domain.org.crt.key.conf:1:  ssl_dhparam /usr/local/nginx/conf/ssl/domain.org/dhparam.pem;
    /usr/local/nginx/conf/ssl/domain.org/domain.org.crt.key.conf:2:  ssl_certificate      /usr/local/nginx/conf/ssl/domain.org/domain.org-acme.cer;
    /usr/local/nginx/conf/ssl/domain.org/domain.org.crt.key.conf:3:  ssl_certificate_key  /usr/local/nginx/conf/ssl/domain.org/domain.org-acme.key;
    /usr/local/nginx/conf/ssl/domain.org/domain.org.crt.key.conf:4:  ssl_trusted_certificate /usr/local/nginx/conf/ssl/domain.org/domain.org-acme.cer;
    /usr/local/nginx/conf/autoprotect/domain.org/autoprotect-domain.org.conf:1:# /home/nginx/domains/domain.org/public/wp-content/plugins/akismet
    /usr/local/nginx/conf/acmevhostbackup/domain.org.conf-backup-removal-https-default-121017-045858:9:#            server_name domain.org www.domain.org;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.conf-backup-removal-https-default-121017-045858:10:#            return 301 $scheme://www.domain.org$request_uri;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.conf-backup-removal-https-default-121017-045858:15:  server_name domain.org www.domain.org;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.conf-backup-removal-https-default-121017-045858:29:  access_log /home/nginx/domains/domain.org/log/access.log combined buffer=256k flush=5m;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.conf-backup-removal-https-default-121017-045858:30:  error_log /home/nginx/domains/domain.org/log/error.log;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.conf-backup-removal-https-default-121017-045858:32:  include /usr/local/nginx/conf/autoprotect/domain.org/autoprotect-domain.org.conf;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.conf-backup-removal-https-default-121017-045858:33:  root /home/nginx/domains/domain.org/public;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.conf-backup-removal-https-default-121017-045858:56:  include /usr/local/nginx/conf/pre-staticfiles-local-domain.org.conf;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.conf-backup-removal-https-default-121017-043042:9:#            server_name domain.org;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.conf-backup-removal-https-default-121017-043042:10:#            return 301 $scheme://www.domain.org$request_uri;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.conf-backup-removal-https-default-121017-043042:15:  server_name domain.org www.domain.org;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.conf-backup-removal-https-default-121017-043042:29:  access_log /home/nginx/domains/domain.org/log/access.log combined buffer=256k flush=5m;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.conf-backup-removal-https-default-121017-043042:30:  error_log /home/nginx/domains/domain.org/log/error.log;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.conf-backup-removal-https-default-121017-043042:32:  include /usr/local/nginx/conf/autoprotect/domain.org/autoprotect-domain.org.conf;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.conf-backup-removal-https-default-121017-043042:33:  root /home/nginx/domains/domain.org/public;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.conf-backup-removal-https-default-121017-043042:56:  include /usr/local/nginx/conf/pre-staticfiles-local-domain.org.conf;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.ssl.conf-acmebackup-121017-043042:12:  server_name domain.org www.domain.org;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.ssl.conf-acmebackup-121017-043042:18:  server_name domain.org www.domain.org;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.ssl.conf-acmebackup-121017-043042:20:  include /usr/local/nginx/conf/ssl/domain.org/domain.org.crt.key.conf;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.ssl.conf-acmebackup-121017-043042:53:  access_log /home/nginx/domains/domain.org/log/access.log combined buffer=256k flush=5m;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.ssl.conf-acmebackup-121017-043042:54:  error_log /home/nginx/domains/domain.org/log/error.log;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.ssl.conf-acmebackup-121017-043042:56:  include /usr/local/nginx/conf/autoprotect/domain.org/autoprotect-domain.org.conf;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.ssl.conf-acmebackup-121017-043042:57:  root /home/nginx/domains/domain.org/public;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.ssl.conf-acmebackup-121017-043042:80:  include /usr/local/nginx/conf/pre-staticfiles-local-domain.org.conf;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.ssl.conf-acmebackup-121017-045858:12:  server_name domain.org www.domain.org;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.ssl.conf-acmebackup-121017-045858:18:  server_name domain.org www.domain.org;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.ssl.conf-acmebackup-121017-045858:20:  include /usr/local/nginx/conf/ssl/domain.org/domain.org.crt.key.conf;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.ssl.conf-acmebackup-121017-045858:53:  access_log /home/nginx/domains/domain.org/log/access.log combined buffer=256k flush=5m;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.ssl.conf-acmebackup-121017-045858:54:  error_log /home/nginx/domains/domain.org/log/error.log;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.ssl.conf-acmebackup-121017-045858:56:  include /usr/local/nginx/conf/autoprotect/domain.org/autoprotect-domain.org.conf;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.ssl.conf-acmebackup-121017-045858:57:  root /home/nginx/domains/domain.org/public;
    /usr/local/nginx/conf/acmevhostbackup/domain.org.ssl.conf-acmebackup-121017-045858:80:  include /usr/local/nginx/conf/pre-staticfiles-local-domain.org.conf;
    /usr/local/nginx/conf/conf.d/domain.org.ssl.conf:5:  server_name domain.org www.domain.org;
    /usr/local/nginx/conf/conf.d/domain.org.ssl.conf:6:  return 302 https://www.domain.org$request_uri;
    /usr/local/nginx/conf/conf.d/domain.org.ssl.conf:11:  server_name domain.org www.domain.org;
    /usr/local/nginx/conf/conf.d/domain.org.ssl.conf:13:  include /usr/local/nginx/conf/ssl/domain.org/domain.org.crt.key.conf;
    /usr/local/nginx/conf/conf.d/domain.org.ssl.conf:46:  access_log /home/nginx/domains/domain.org/log/access.log combined buffer=256k flush=5m;
    /usr/local/nginx/conf/conf.d/domain.org.ssl.conf:47:  error_log /home/nginx/domains/domain.org/log/error.log;
    /usr/local/nginx/conf/conf.d/domain.org.ssl.conf:49:  include /usr/local/nginx/conf/autoprotect/domain.org/autoprotect-domain.org.conf;
    /usr/local/nginx/conf/conf.d/domain.org.ssl.conf:50:  root /home/nginx/domains/domain.org/public;
    /usr/local/nginx/conf/conf.d/domain.org.ssl.conf:78:  include /usr/local/nginx/conf/pre-staticfiles-local-domain.org.conf;
    

     
  2. eva2000

    eva2000 Administrator Staff Member

    45,728
    10,382
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +16,112
    Local Time:
    1:12 PM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    strange looks good there too with no 301 permanent redirects ! are you behind clouldfare ? you do have DNS A records for both www and non-www version of domain.org ?
     
  3. Jon Snow

    Jon Snow Active Member

    593
    92
    28
    Jun 30, 2017
    Ratings:
    +147
    Local Time:
    11:12 PM
    Nginx 1.13.9
    MariaDB 10.1.31
    No cloudflare. DNS has been set up for both www and non-www.

    I do have the domain and IP in my HOST file on my computer. Maybe that caused this? - acmetool.sh redirects www to non-www
     
  4. eva2000

    eva2000 Administrator Staff Member

    45,728
    10,382
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +16,112
    Local Time:
    1:12 PM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    try removing local hosts file edits
     
  5. Jon Snow

    Jon Snow Active Member

    593
    92
    28
    Jun 30, 2017
    Ratings:
    +147
    Local Time:
    11:12 PM
    Nginx 1.13.9
    MariaDB 10.1.31
    Didn't seem to change a thing.
     
  6. eva2000

    eva2000 Administrator Staff Member

    45,728
    10,382
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +16,112
    Local Time:
    1:12 PM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    strange there's no mention for permanent redirect 301 in any of your vhosts either ! maybe try searching for references to 301 in all vhosts and see
    Code (Text):
    egrep -rn '301|permanent' /usr/local/nginx/conf
    
     
  7. Jon Snow

    Jon Snow Active Member

    593
    92
    28
    Jun 30, 2017
    Ratings:
    +147
    Local Time:
    11:12 PM
    Nginx 1.13.9
    MariaDB 10.1.31
    Everything looks fine here to me :
    Code (Text):
    egrep -rn '301|permanent' /usr/local/nginx/conf
    /usr/local/nginx/conf/wpnocache.conf:2:rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    /usr/local/nginx/conf/acmevhostbackup/problem-domain.org.conf-backup-removal-https-default-121017-045858:6:# if unsure use return 302 before using return 301
    /usr/local/nginx/conf/acmevhostbackup/problem-domain.org.conf-backup-removal-https-default-121017-045858:10:#            return 301 $scheme://www.problem-domain.org$request_uri;
    /usr/local/nginx/conf/acmevhostbackup/domain-is-fine.com.conf-backup-removal-https-default-081017-082410:6:# if unsure use return 302 before using return 301
    /usr/local/nginx/conf/acmevhostbackup/domain-is-fine.com.conf-backup-removal-https-default-081017-082410:10:#            return 301 $scheme://www.domain-is-fine.com$request_uri;
    /usr/local/nginx/conf/acmevhostbackup/problem-domain.org.conf-backup-removal-https-default-121017-043042:6:# if unsure use return 302 before using return 301
    /usr/local/nginx/conf/acmevhostbackup/problem-domain.org.conf-backup-removal-https-default-121017-043042:10:#            return 301 $scheme://www.problem-domain.org$request_uri;
    /usr/local/nginx/conf/acmevhostbackup/problem-domain.org.ssl.conf-acmebackup-121017-043042:8:# if unsure use return 302 before using return 301
    /usr/local/nginx/conf/acmevhostbackup/problem-domain.org.ssl.conf-acmebackup-121017-045858:8:# if unsure use return 302 before using return 301
    /usr/local/nginx/conf/acmevhostbackup/domain-is-fine.com.ssl.conf-acmebackup-081017-082410:8:# if unsure use return 302 before using return 301
    /usr/local/nginx/conf/conf.d/demodomain.com.conf:6:            return 301 $scheme://www.demodomain.com$request_uri;
    /usr/local/nginx/conf/conf.d/domain-is-fine.com.ssl.conf:14:         return 301 https://www.domain-is-fine.com$request_uri;
    

    problem-domain.org is the domain with the issue. I ran the tool to create the vhost.
    domain-is-fine.com is the domain with no problem. I manually set up SSL using the tool.
     
  8. eva2000

    eva2000 Administrator Staff Member

    45,728
    10,382
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +16,112
    Local Time:
    1:12 PM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    indeed looks good there too.. very strange that you get 301 redirect still
     
  9. Jon Snow

    Jon Snow Active Member

    593
    92
    28
    Jun 30, 2017
    Ratings:
    +147
    Local Time:
    11:12 PM
    Nginx 1.13.9
    MariaDB 10.1.31
    Have you tried to reproduce it on a test server?
     
  10. eva2000

    eva2000 Administrator Staff Member

    45,728
    10,382
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +16,112
    Local Time:
    1:12 PM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    Yes i don't have that problem on any server. You might need to recompile nginx in debug mode and check logs to troubleshoot

    Try enabling nginx debug mode for your ISP ip only and see if logs reveal more.

    To enable, add to persistent config file /etc/centminmod/custom_config.inc the variable NGINX_DEBUG=y and recompile Nginx via centmin.sh menu option 4 and then setting error_log in nginx vhosts to debug as outlined at nginx.org/en/docs/debugging_log.html & wiki.nginx.org/Debugging.

    You do not want to leave Nginx debug mode running forever, so after debugging, set NGINX_DEBUG=n or remove the variable from the persistent config file /etc/centminmod/custom_config.inc and recompile Nginx again via centmin.sh menu option 4 and remove error_log debugging mode to disable Nginx debug mode again.

    Centmin Mod is provided as is, but you can try debugging mode for Nginx for further troubleshooting if you have problems with Nginx (i.e. segfaults / signal 11 issues) as outlined at nginx.org/en/docs/debugging_log.html & wiki.nginx.org/Debugging.