Welcome to Centmin Mod Community
Register Now

Nginx Domain showing default Centmin test page.

Discussion in 'Install & Upgrades or Pre-Install Questions' started by pheonis, Feb 10, 2020.

Tags:
  1. pheonis

    pheonis Member

    62
    3
    8
    Dec 21, 2018
    Ratings:
    +4
    Local Time:
    7:22 AM
    Please fill in any relevant information that applies to you:
    • CentOS Version: CentOS 7 64bit ?
    • Centmin Mod Version Installed:123.09beta01
    • Nginx Version Installed: i.e. 1.15.3
    • PHP Version Installed: 7.2.9
    • MariaDB MySQL Version Installed:10.2.xx
    i have created vhost and installed WordPress using 22 menu.

    Created 3 A records (domain.com, www, hostname) in cloudflare all pointing to the server ip.

    My website is showing default centmin test page. I am aware of hostname and its different than my domain.
    My hostname.domain.com, domain.com, server ip all showing the centmin page.

    Output of
    Code:
    dig +short A @8.8.8.8 yourdomain.com
    dig +short A @8.8.8.8 www.yourdomain.com
    dig +short A @8.8.8.8 hostname.yourdomain.com
    Shows My cloudflare Server IPs.

    Output of Curl


    Code:
    [11:33][root@hostname.domain.com ~]# curl -I http://domain.com
    HTTP/1.1 200 OK
    Date: Mon, 10 Feb 2020 11:36:02 GMT
    Content-Type: text/html; charset=UTF-8
    Connection: keep-alive
    Set-Cookie: __cfduid=df978814383d92d38e02c5f8335d582401581334562; expires=Wed, 11-Mar-20 11:36:02 GMT; path=/; domain=.domain.com; HttpOnly; SameSite=Lax
    Vary: Accept-Encoding
    X-Powered-By: centminmod
    X-Page-Speed: 1.13.35.2-0
    Cache-Control: max-age=86400
    CF-Cache-Status: MISS
    Server: cloudflare
    CF-RAY: 562dc8799a7fe4cc-LAX
    
    [11:36][root@hostname.domain.com ~]# curl -I http://www.domain.com
    HTTP/1.1 200 OK
    Date: Mon, 10 Feb 2020 11:39:07 GMT
    Content-Type: text/html; charset=UTF-8
    Connection: keep-alive
    Set-Cookie: __cfduid=d028f7b34c97f17066ea1f62b1af5b3e41581334747; expires=Wed, 11-Mar-20 11:39:07 GMT; path=/; domain=.domain.com; HttpOnly; SameSite=Lax
    Vary: Accept-Encoding
    X-Powered-By: centminmod
    X-Page-Speed: 1.13.35.2-0
    Cache-Control: max-age=86400
    CF-Cache-Status: MISS
    Server: cloudflare
    CF-RAY: 562dccfbbb1beb61-LAX
    
    [11:39][root@hostname.domain.com ~]# curl -I https://www.domain.com
    HTTP/1.1 301 Moved Permanently
    Date: Mon, 10 Feb 2020 11:43:01 GMT
    Content-Type: text/html; charset=UTF-8
    Connection: keep-alive
    Set-Cookie: __cfduid=d4ba286138fd5a9230a6dfa5e6db07cf31581334980; expires=Wed, 11-Mar-20 11:43:00 GMT; path=/; domain=.domain.com; HttpOnly; SameSite=Lax; Secure
    X-Redirect-By: WordPress
    Location: https://domain.com/
    X-Powered-By: centminmod
    X-Xss-Protection: 1; mode=block
    X-Content-Type-Options: nosniff
    X-Page-Speed: 1.13.35.2-0
    Cache-Control: max-age=0, no-cache
    CF-Cache-Status: DYNAMIC
    Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
    Server: cloudflare
    CF-RAY: 562dd2aece82e4fe-LAX
    
    [11:43][root@hostname.domain.com ~]# curl -I https://domain.com HTTP/1.1 200 OK
    Date: Mon, 10 Feb 2020 11:45:30 GMT
    Content-Type: text/html; charset=UTF-8
    Connection: keep-alive
    Set-Cookie: __cfduid=dbc28b56ef591ffd295b8629586268fd51581335130; expires=Wed, 11-Mar-20 11:45:30 GMT; path=/; domain=.domain.com; HttpOnly; SameSite=Lax; Secure
    Vary: Accept-Encoding
    X-Powered-By: centminmod
    X-Page-Speed: 1.13.35.2-0
    Cache-Control: max-age=0, no-cache
    CF-Cache-Status: DYNAMIC
    Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
    Server: cloudflare
    CF-RAY: 562dd6543ef8ebc9-LAX
    

    Code:
    [12:14][root@hostname ~]# hostnamectl status
       Static hostname: hostname.domain.com
             Icon name: computer-container
               Chassis: container
            Machine ID: cd4f7fdd8e1347c29e883225f5d01a5c
               Boot ID: 46223462c998465a9778c8880a7a3f81
        Virtualization: openvz
      Operating System: CentOS Linux 7 (Core)
           CPE OS Name: cpe:/o:centos:centos:7
                Kernel: Linux 2.6.32-042stab133.2
          Architecture: x86-64
    
    Server name in virtual.conf is set to
    Code:
    hostname.domain.com
    DOcument root set to /home/nginx/domains/domain.com/public in /usr/local/nginx/conf/conf.d/domain.com.ssl.conf

    I dont understand where im going wrong. Everything i perfect but im not able to solve it. Please help.
     
    Last edited: Feb 10, 2020
  2. eva2000

    eva2000 Administrator Staff Member

    44,448
    10,153
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,710
    Local Time:
    11:52 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    Your HTTPS version of your www domain shows wordpress headers while rest don't so looks like you haven't properly configured default HTTPS redirect/defaults or something for non-HTTPS www/non-www and HTTPS non-www.

    When you create a new nginx vhost domain via centmin.sh menu option 2 or menu option 22 or via /usr/bin/nv cli command line, you will create the Nginx vhost files and directories. You will get an outputted the path location where it will create the domain name's vhost conf file named newdomain.com.conf (and newdomain.com.ssl.conf if you selected yes to self signed SSL)
    • Nginx vhost conf path will be at /usr/local/nginx/conf/conf.d/newdomain.com.conf
    • Nginx HTTP/2 SSL vhost conf path will be at /usr/local/nginx/conf/conf.d/newdomain.com.ssl.conf
    • Nginx Self-Signed SSL Certificate Directory at /usr/local/nginx/conf/ssl/newdomain.com
    • Vhost public web root will be at /home/nginx/domains/newdomain.com/public
    • Vhost log directory will be at /home/nginx/domains/newdomain.com/log
    Please post the contents of /usr/local/nginx/conf/conf.d/newdomain.com.conf and if applicable /usr/local/nginx/conf/conf.d/newdomain.com.ssl.conf wrapped in CODE tags (outlined at How to use forum BBCODE code tags)

    Also post contents of main hostname's nginx vhost at /usr/local/nginx/conf/conf.d/virtual.conf as outlined at https://centminmod.com/configfiles.html
     
  3. pheonis

    pheonis Member

    62
    3
    8
    Dec 21, 2018
    Ratings:
    +4
    Local Time:
    7:22 AM
    I have disabled the domain.con.conf.

    Here are the outputs of domain.com.ssl.conf
    Code:
    # Centmin Mod Getting Started Guide
    # must read http://centminmod.com/getstarted.html
    # For HTTP/2 SSL Setup
    # read http://centminmod.com/nginx_configure_https_ssl_spdy.html
    
    # redirect from www to non-www  forced SSL
    # uncomment, save file and restart Nginx to enable
    # if unsure use return 302 before using return 301
    # server {
    #   server_name domain.com www.domain.com;
    #    return 302 https://$server_name$request_uri;
    # }
    
     server {
        server_name domain.com www.domain.com;
     #   return 302 https://www.domain.com$request_uri;
     }
    
    server {
    
      listen 443 ssl http2;
      server_name www.domain.com;
      ssl_dhparam /usr/local/nginx/conf/ssl/domain.com/dhparam.pem;
      ssl_certificate      /usr/local/nginx/conf/ssl/celebdailynews.com/celebdailynews.com.crt;
      ssl_certificate_key  /usr/local/nginx/conf/ssl/celebdailynews.com/celebdailynews.com.key;
      include /usr/local/nginx/conf/ssl_include.conf;
    
      # cloudflare authenticated origin pull cert community.centminmod.com/threads/13847/
      #ssl_client_certificate /usr/local/nginx/conf/ssl/cloudflare/celebdailynews.com/origin.crt;
      #ssl_verify_client on;
      http2_max_field_size 16k;
      http2_max_header_size 32k;
      http2_max_requests 5000;
      # mozilla recommended
     ssl_ciphers TLS13-AES-128-GCM-SHA256:TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-A
      ssl_prefer_server_ciphers   on;
      #add_header Alternate-Protocol  443:npn-spdy/3;
    
      # before enabling HSTS line below read centminmod.com/nginx_domain_dns_setup.html#hsts
      #add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
      #add_header X-Frame-Options SAMEORIGIN;
      add_header X-Xss-Protection "1; mode=block" always;
      add_header X-Content-Type-Options "nosniff" always;
      #add_header Referrer-Policy "strict-origin-when-cross-origin";
     #add_header Feature-Policy "accelerometer 'none'; camera 'none'; geolocation 'none'; gyroscope 'none'; magnetometer 'none'; microphone 'none'; payment 'none'; usb 'none'";
      #spdy_headers_comp 5;
      ssl_buffer_size 1369;
      ssl_session_tickets on;
    
      # enable ocsp stapling
      #resolver 8.8.8.8 8.8.4.4 1.1.1.1 1.0.0.1 valid=10m;
      #resolver_timeout 10s;
      #ssl_stapling on;
      #ssl_stapling_verify on;
      #ssl_trusted_certificate /usr/local/nginx/conf/ssl/celebdailynews.com/celebdailynews.com-trusted.crt;
    
    # ngx_pagespeed & ngx_pagespeed handler
    #include /usr/local/nginx/conf/pagespeed.conf;
    #include /usr/local/nginx/conf/pagespeedhandler.conf;
    #include /usr/local/nginx/conf/pagespeedstatslog.conf;
    
      # limit_conn limit_per_ip 16;
      # ssi  on;
    
       access_log /home/nginx/domains/celebdailynews.com/log/access.log combined buffer=256k flush=5m;
      error_log /home/nginx/domains/celebdailynews.com/log/error.log;
    
      include /usr/local/nginx/conf/autoprotect/celebdailynews.com/autoprotect-celebdailynews.com.conf;
      root /home/nginx/domains/domain.com/public;
      # uncomment cloudflare.conf include if using cloudflare for
      # server and/or vhost site
      include /usr/local/nginx/conf/cloudflare.conf;
      include /usr/local/nginx/conf/503include-main.conf;
    
       include /usr/local/nginx/conf/wpincludes/celebdailynews.com/wpcacheenabler_celebdailynews.com.conf;
      #include /usr/local/nginx/conf/wpincludes/celebdailynews.com/wpsupercache_celebdailynews.com.conf;
      # https://community.centminmod.com/posts/18828/
      #include /usr/local/nginx/conf/wpincludes/celebdailynews.com/rediscache_celebdailynews.com.conf;
    
      location / {
      include /usr/local/nginx/conf/503include-only.conf;
    
    
      # Enables directory listings when index file not found
      #autoindex  on;
    
      # for wordpress super cache plugin
    #try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php?q=$uri&$args;
    
    
      # for wp cache enabler plugin
     try_files $cache_enabler_uri $uri $uri/ $custom_subdir/index.php?$args;
    
      # Wordpress Permalinks
      #try_files $uri $uri/ /index.php?q=$uri&$args;
    
      # Nginx level redis Wordpress
      # https://community.centminmod.com/posts/18828/
      #try_files $uri $uri/ /index.php?$args;
    
      }
    
    location ~* /(wp-login\.php) {
        limit_req zone=xwplogin burst=1 nodelay;
        #limit_conn xwpconlimit 30;
        #auth_basic "Private";
        #auth_basic_user_file /home/nginx/domains/domain.com/htpasswd_wplogin;
        include /usr/local/nginx/conf/php-wpsc.conf;
    
        # https://community.centminmod.com/posts/18828/
        #include /usr/local/nginx/conf/php-rediscache.conf;
    }
    
    location ~* /(xmlrpc\.php) {
       limit_req zone=xwprpc burst=45 nodelay;
        #limit_conn xwpconlimit 30;
        include /usr/local/nginx/conf/php-wpsc.conf;
    
        # https://community.centminmod.com/posts/18828/
        #include /usr/local/nginx/conf/php-rediscache.conf;
    }
    
    location ~* /wp-admin/(load-scripts\.php) {
        limit_req zone=xwprpc burst=5 nodelay;
        #limit_conn xwpconlimit 30;
        include /usr/local/nginx/conf/php-wpsc.conf;
    
        # https://community.centminmod.com/posts/18828/
        #include /usr/local/nginx/conf/php-rediscache.conf;
    }
    
    location ~* /wp-admin/(load-styles\.php) {
        limit_req zone=xwprpc burst=5 nodelay;
        #limit_conn xwpconlimit 30;
        include /usr/local/nginx/conf/php-wpsc.conf;
    
        # https://community.centminmod.com/posts/18828/
    
        #include /usr/local/nginx/conf/php-rediscache.conf;
    }
    
      include /usr/local/nginx/conf/wpincludes/celebdailynews.com/wpsecure_celebdailynews.com.conf;
      include /usr/local/nginx/conf/php-wpsc.conf;
    
      # https://community.centminmod.com/posts/18828/
      #include /usr/local/nginx/conf/php-rediscache.conf;
      include /usr/local/nginx/conf/pre-staticfiles-local-domain.com.conf;
      include /usr/local/nginx/conf/pre-staticfiles-global.conf;
      include /usr/local/nginx/conf/staticfiles.conf;
      include /usr/local/nginx/conf/drop.conf;
      #include /usr/local/nginx/conf/errorpage.conf;
      include /usr/local/nginx/conf/vts_server.conf;
    }
    
    
    Output of domain.com.conf-disabled

    Code:
    # Centmin Mod Getting Started Guide
    # must read http://centminmod.com/getstarted.html
    
    # redirect from non-www to www
    # uncomment, save file and restart Nginx to enable
    # if unsure use return 302 before using return 301
    #server {
    #            listen   80;
    #            server_name domain.com;
    #            return 301 $scheme://www.domain.com$request_uri;
    #       }
    
    server {
    
      server_name domain.com www.domain.com;
    
    # ngx_pagespeed & ngx_pagespeed handler
    #include /usr/local/nginx/conf/pagespeed.conf;
    #include /usr/local/nginx/conf/pagespeedhandler.conf;
    #include /usr/local/nginx/conf/pagespeedstatslog.conf;
    
      #add_header X-Frame-Options SAMEORIGIN;
      add_header X-Xss-Protection "1; mode=block" always;
      add_header X-Content-Type-Options "nosniff" always;
      #add_header Referrer-Policy "strict-origin-when-cross-origin";
      #add_header Feature-Policy "accelerometer 'none'; camera 'none'; geolocation 'none'; gyroscope 'none'; magnetometer 'none'; microphone 'none'; payment 'none'; usb 'none'";
    
      # limit_conn limit_per_ip 16;
      # ssi  on;
    
      access_log /home/nginx/domains/domain.com/log/access.log combined buffer=256k flush=5m;
      error_log /home/nginx/domains/domain.com/log/error.log;
    
      include /usr/local/nginx/conf/autoprotect/domain.com/autoprotect-domain.com.conf;
      root /home/nginx/domains/domain.com/public;
      # uncomment cloudflare.conf include if using cloudflare for
      # server and/or vhost site
      #include /usr/local/nginx/conf/cloudflare.conf;
      include /usr/local/nginx/conf/503include-main.conf;
    
      include /usr/local/nginx/conf/wpincludes/domain.com/wpcacheenabler_domain.com.conf;
      #include /usr/local/nginx/conf/wpincludes/domain.com/wpsupercache_domain.com.conf;
      # https://community.centminmod.com/posts/18828/
      #include /usr/local/nginx/conf/wpincludes/domain.com/rediscache_domain.com.conf;
     location / {
      include /usr/local/nginx/conf/503include-only.conf;
    
    
      # Enables directory listings when index file not found
      #autoindex  on;
    
      # for wordpress super cache plugin
      #try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php?q=$uri&$args;
    
      # for wp cache enabler plugin
      try_files $cache_enabler_uri $uri $uri/ $custom_subdir/index.php?$args;
    
      # Wordpress Permalinks
      #try_files $uri $uri/ /index.php?q=$uri&$args;
    
      # Nginx level redis Wordpress
      # https://community.centminmod.com/posts/18828/
      #try_files $uri $uri/ /index.php?$args;
    
      }
    location ~* /(wp-login\.php) {
        limit_req zone=xwplogin burst=1 nodelay;
        #limit_conn xwpconlimit 30;
        #auth_basic "Private";
        #auth_basic_user_file /home/nginx/domains/domain.com/htpasswd_wplogin;
        include /usr/local/nginx/conf/php-wpsc.conf;
        # https://community.centminmod.com/posts/18828/
        #include /usr/local/nginx/conf/php-rediscache.conf;
    }
    
    location ~* /(xmlrpc\.php) {
        limit_req zone=xwprpc burst=45 nodelay;
        #limit_conn xwpconlimit 30;
        include /usr/local/nginx/conf/php-wpsc.conf;
        # https://community.centminmod.com/posts/18828/
        #include /usr/local/nginx/conf/php-rediscache.conf;
    }
    
    location ~* /wp-admin/(load-scripts\.php) {
        limit_req zone=xwprpc burst=5 nodelay;
        #limit_conn xwpconlimit 30;
        include /usr/local/nginx/conf/php-wpsc.conf;
        # https://community.centminmod.com/posts/18828/
    
        #include /usr/local/nginx/conf/php-rediscache.conf;
    }
    
    location ~* /wp-admin/(load-styles\.php) {
        limit_req zone=xwprpc burst=5 nodelay;
        #limit_conn xwpconlimit 30;
        include /usr/local/nginx/conf/php-wpsc.conf;
        # https://community.centminmod.com/posts/18828/
        #include /usr/local/nginx/conf/php-rediscache.conf;
    }
    
      include /usr/local/nginx/conf/wpincludes/domain.com/wpsecure_domain.com.conf;
      include /usr/local/nginx/conf/php-wpsc.conf;
    
      # https://community.centminmod.com/posts/18828/
      #include /usr/local/nginx/conf/php-rediscache.conf;
      include /usr/local/nginx/conf/pre-staticfiles-local-domain.com.conf;
      include /usr/local/nginx/conf/pre-staticfiles-global.conf;
      include /usr/local/nginx/conf/staticfiles.conf;
      include /usr/local/nginx/conf/drop.conf;
      #include /usr/local/nginx/conf/errorpage.conf;
      include /usr/local/nginx/conf/vts_server.conf;
    }
    
    
    Output of /usr/local/nginx/conf/conf.d/virtual.conf

    Code:
    server {
                listen 80 default_server backlog=2048 reuseport;
                server_name hostname.domain.com;
                root   html;
    
            access_log              /var/log/nginx/localhost.access.log     combine$
            error_log               /var/log/nginx/localhost.error.log      error;
    
    # ngx_pagespeed & ngx_pagespeed handler
    #include /usr/local/nginx/conf/pagespeed.conf;
    #include /usr/local/nginx/conf/pagespeedhandler.conf;
    #include /usr/local/nginx/conf/pagespeedstatslog.conf;
    
    # limit_conn limit_per_ip 16;
    # ssi  on;
    
            location /nginx_status {
            stub_status on;
            access_log   off;
            allow 127.0.0.1;
            #allow youripaddress;
            deny all;
            }
    
                location / {
    
    # block common exploits, sql injections etc
    #include /usr/local/nginx/conf/block.conf;
    
    #Enables directory listings when index file not found
    #autoindex  on;
    
    #Shows file listing times as local time
    #autoindex_localtime on;
    
    # Wordpress Permalinks example
    #try_files \$uri \$uri/ /index.php?q=\$uri&\$args;
    
                }
    
    include /usr/local/nginx/conf/staticfiles.conf;
    include /usr/local/nginx/conf/include_opcache.conf;
    include /usr/local/nginx/conf/php.conf;
    include /usr/local/nginx/conf/phpstatus.conf;
    include /usr/local/nginx/conf/drop.conf;
    #include /usr/local/nginx/conf/errorpage.conf;
    #include /usr/local/nginx/conf/vts_mainserver.conf;
    
           }
    
    
    CURL output

    Code:
    curl -I http://domain.com
    HTTP/1.1 301 Moved Permanently
    Date: Wed, 12 Feb 2020 03:29:45 GMT
    Connection: keep-alive
    Cache-Control: max-age=3600
    Expires: Wed, 12 Feb 2020 04:29:45 GMT
    Location: https://domain.com/
    Server: cloudflare
    CF-RAY: 563b7ae158f0e4c4-LAX
    
    [03:29][root@hostname.domain.com ~]# curl -I http://www.domain.com
    HTTP/1.1 301 Moved Permanently
    Date: Wed, 12 Feb 2020 03:32:12 GMT
    Connection: keep-alive
    Cache-Control: max-age=3600
    Expires: Wed, 12 Feb 2020 04:32:12 GMT
    Location: https://www.domain.com/
    Server: cloudflare
    CF-RAY: 563b7e7ace91770a-LAX
    
    [03:32][root@hostname.domain.com ~]# curl -I https://domain.com
    HTTP/1.1 200 OK
    Date: Wed, 12 Feb 2020 03:35:24 GMT
    Content-Type: text/html; charset=utf-8
    Connection: keep-alive
    Set-Cookie: __cfduid=d3737b83c11b806d3d54f6c6fc2d7072d1581478524; expires=Fri, 13-Mar-20 03:35:24 GMT; path=/; domain=.domain.com; HttpOnly; SameSite=Lax; Secure
    Vary: Accept-Encoding
    X-Powered-By: centminmod
    X-Xss-Protection: 1; mode=block
    X-Content-Type-Options: nosniff
    X-Page-Speed: 1.13.35.2-0
    Cache-Control: max-age=0, no-cache
    CF-Cache-Status: DYNAMIC
    Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
    Server: cloudflare
    CF-RAY: 563b832cdc9beb55-LAX
    
    [03:35][root@hostname.domain.com ~]# curl -I https://www.domain.com
    HTTP/1.1 301 Moved Permanently
    Date: Wed, 12 Feb 2020 03:37:52 GMT
    Content-Type: text/html; charset=UTF-8
    Connection: keep-alive
    Set-Cookie: __cfduid=dc753d2027adf1157f621a2fe2b5a0f591581478671; expires=Fri, 13-Mar-20 03:37:51 GMT; path=/; domain=.domain.com; HttpOnly; SameSite=Lax; Secure
    X-Redirect-By: WordPress
    Location: https://domain.com/
    X-Powered-By: centminmod
    X-Xss-Protection: 1; mode=block
    X-Content-Type-Options: nosniff
    X-Page-Speed: 1.13.35.2-0
    Cache-Control: max-age=0, no-cache
    CF-Cache-Status: DYNAMIC
    Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
    Server: cloudflare
    CF-RAY: 563b86c27a2b7800-LAX
    
    
     
    Last edited: Feb 12, 2020
  4. eva2000

    eva2000 Administrator Staff Member

    44,448
    10,153
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,710
    Local Time:
    11:52 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    Posted at centminmod.com/nginx_domain_dns_setup.html#httpsredirect is the correct way to set it up - pay attention to different way if you want redirect target being www version instead of non-www and vice versa and that the target version www or non-www is the only version listed in server_name for the 2nd/main server {} context.

    And if you want HTTPS default www target domain
    so ends up being something like
    Code (Text):
    # Centmin Mod Getting Started Guide
    # must read http://centminmod.com/getstarted.html
    # For HTTP/2 SSL Setup
    # read http://centminmod.com/nginx_configure_https_ssl_spdy.html
    
    # redirect from www to non-www  forced SSL
    # uncomment, save file and restart Nginx to enable
    # if unsure use return 302 before using return 301
     server {
       server_name newdomain.com www.newdomain.com;
        return 302 https://www.newdomain.com$request_uri;
     }
    
    server {
      listen 443 ssl http2;
      server_name newdomain.com;
      return 302 https://www.newdomain.com$request_uri;
    
      ssl_dhparam /usr/local/nginx/conf/ssl/newdomain.com/dhparam.pem;
      ssl_certificate      /usr/local/nginx/conf/ssl/newdomain.com/newdomain.com.crt;
      ssl_certificate_key  /usr/local/nginx/conf/ssl/newdomain.com/newdomain.com.key;
      include /usr/local/nginx/conf/ssl_include.conf;
    }
    
    server {
      listen 443 ssl http2;
      server_name www.newdomain.com;
    
      ssl_dhparam /usr/local/nginx/conf/ssl/newdomain.com/dhparam.pem;
      ssl_certificate      /usr/local/nginx/conf/ssl/newdomain.com/newdomain.com.crt;
      ssl_certificate_key  /usr/local/nginx/conf/ssl/newdomain.com/newdomain.com.key;
      include /usr/local/nginx/conf/ssl_include.conf;
    
    < snipped the rest of the nginx settings >

    Notice the middle server{} context tells Nginx to redirect non-www domain HTTPS requests to www domain HTTPS requests for www domain on third server{} context. While first server{} context tells Nginx to redirect both non-HTTPS non-www and www domain requests to HTTPS requests for www domain on third server{} context.

    key to testing is using 302 temp redirect first in a private incognito browser session otherwise the problems you can experience may end up being due to browser caching or 301 permanent redirects unless you clear browser cache and reboot local computer(s) and even then some web browsers don't let go of 301 permanent redirect browser cache that willingly :)

    You can test in SSH via curl to check headers for location field (where the redirect goes) using the following commands:
    Code (Text):
    curl -I http://domain.com
    

    Code (Text):
    curl -I http://www.domain.com
    
     
  5. pheonis

    pheonis Member

    62
    3
    8
    Dec 21, 2018
    Ratings:
    +4
    Local Time:
    7:22 AM
    After I set the server {} as per your advice. I am getting "ERR_TOO_MANY_REDIRECTS" error

    My domain.com.ssl.conf content.
    Code:
    # Centmin Mod Getting Started Guide
    # must read http://centminmod.com/getstarted.html
    # For HTTP/2 SSL Setup
    # read http://centminmod.com/nginx_configure_https_ssl_spdy.html
    
    # redirect from www to non-www  forced SSL
    # uncomment, save file and restart Nginx to enable
    # if unsure use return 302 before using return 301
    # server {
    #   server_name domain.com www.domain.com;
    #    return 302 https://$server_name$request_uri;
    # }
    
     server {
        server_name domain.com www.domain.com;
        return 302 https://www.domain.com$request_uri;
     }
    
    
    server {
    
      listen 443 ssl http2;
      server_name domain.com;
      return 302 https://www.domain.com$request_uri;
    
      ssl_dhparam /usr/local/nginx/conf/ssl/domain.com/dhparam.pem;
      ssl_certificate      /usr/local/nginx/conf/ssl/domain.com/domain.com.crt;
      ssl_certificate_key  /usr/local/nginx/conf/ssl/domain.com/domain.com.key;
      include /usr/local/nginx/conf/ssl_include.conf;
     }
    
    server {
    
      listen 443 ssl http2;
      server_name www.domain.com;
      
      ssl_dhparam /usr/local/nginx/conf/ssl/domain.com/dhparam.pem;
      ssl_certificate      /usr/local/nginx/conf/ssl/domain.com/domain.com.crt;
      ssl_certificate_key  /usr/local/nginx/conf/ssl/domain.com/domain.com.key;
      include /usr/local/nginx/conf/ssl_include.conf;
    
      # cloudflare authenticated origin pull cert community.centminmod.com/threads/13847/
      #ssl_client_certificate /usr/local/nginx/conf/ssl/cloudflare/domain.com/origin.crt;
      #ssl_verify_client on;
      http2_max_field_size 16k;
     http2_max_header_size 32k;
      http2_max_requests 5000;
      # mozilla recommended
      ssl_ciphers TLS13-AES-128-GCM-SHA256:TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-A$
      ssl_prefer_server_ciphers   on;
      #add_header Alternate-Protocol  443:npn-spdy/3;
    
      # before enabling HSTS line below read centminmod.com/nginx_domain_dns_setup.html#hsts
      #add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
      #add_header X-Frame-Options SAMEORIGIN;
      add_header X-Xss-Protection "1; mode=block" always;
      add_header X-Content-Type-Options "nosniff" always;
      #add_header Referrer-Policy "strict-origin-when-cross-origin";
      #add_header Feature-Policy "accelerometer 'none'; camera 'none'; geolocation 'none'; gyroscope 'none'; magnetometer 'none'; microphone 'none'; payment 'none'; usb 'none'";
      #spdy_headers_comp 5;
      ssl_buffer_size 1369;
      ssl_session_tickets on;
    
      # enable ocsp stapling
      #resolver 8.8.8.8 8.8.4.4 1.1.1.1 1.0.0.1 valid=10m;
      #resolver_timeout 10s;
      #ssl_stapling on;
      #ssl_stapling_verify on;
     #ssl_trusted_certificate /usr/local/nginx/conf/ssl/domain.com/domain.com-trusted.crt;
    
    # ngx_pagespeed & ngx_pagespeed handler
    #include /usr/local/nginx/conf/pagespeed.conf;
    #include /usr/local/nginx/conf/pagespeedhandler.conf;
    #include /usr/local/nginx/conf/pagespeedstatslog.conf;
    
      # limit_conn limit_per_ip 16;
      # ssi  on;
    
      access_log /home/nginx/domains/domain.com/log/access.log combined buffer=256k flush=5m;
      error_log /home/nginx/domains/domain.com/log/error.log;
    
      include /usr/local/nginx/conf/autoprotect/domain.com/autoprotect-domain.com.conf;
      root /home/nginx/domains/domain.com/public;
      # uncomment cloudflare.conf include if using cloudflare for
      # server and/or vhost site
      include /usr/local/nginx/conf/cloudflare.conf;
      include /usr/local/nginx/conf/503include-main.conf;
    
      include /usr/local/nginx/conf/wpincludes/domain.com/wpcacheenabler_domain.com.conf;
      #include /usr/local/nginx/conf/wpincludes/domain.com/wpsupercache_domain.com.conf;
      # https://community.centminmod.com/posts/18828/
      #include /usr/local/nginx/conf/wpincludes/domain.com/rediscache_domain.com.conf;
    
      location / {
      include /usr/local/nginx/conf/503include-only.conf;
    
    
      # Enables directory listings when index file not found
      #autoindex  on;
    
      # for wordpress super cache plugin
      #try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php?q=$uri&$args;
    
      # for wp cache enabler plugin
      try_files $cache_enabler_uri $uri $uri/ $custom_subdir/index.php?$args;
    
      # Wordpress Permalinks
      #try_files $uri $uri/ /index.php?q=$uri&$args;
    
      # Nginx level redis Wordpress
      # https://community.centminmod.com/posts/18828/
      #try_files $uri $uri/ /index.php?$args;
     }
    
    location ~* /(wp-login\.php) {
        limit_req zone=xwplogin burst=1 nodelay;
        #limit_conn xwpconlimit 30;
        #auth_basic "Private";
        #auth_basic_user_file /home/nginx/domains/domain.com/htpasswd_wplogin;
        include /usr/local/nginx/conf/php-wpsc.conf;
    
        # https://community.centminmod.com/posts/18828/
        #include /usr/local/nginx/conf/php-rediscache.conf;
    }
    
    location ~* /(xmlrpc\.php) {
        limit_req zone=xwprpc burst=45 nodelay;
        #limit_conn xwpconlimit 30;
        include /usr/local/nginx/conf/php-wpsc.conf;
    
        # https://community.centminmod.com/posts/18828/
        #include /usr/local/nginx/conf/php-rediscache.conf;
    }
    
    location ~* /wp-admin/(load-scripts\.php) {
        limit_req zone=xwprpc burst=5 nodelay;
     #limit_conn xwpconlimit 30;
        include /usr/local/nginx/conf/php-wpsc.conf;
    
        # https://community.centminmod.com/posts/18828/
        #include /usr/local/nginx/conf/php-rediscache.conf;
    }
    
    location ~* /wp-admin/(load-styles\.php) {
        limit_req zone=xwprpc burst=5 nodelay;
        #limit_conn xwpconlimit 30;
        include /usr/local/nginx/conf/php-wpsc.conf;
    
        # https://community.centminmod.com/posts/18828/
        #include /usr/local/nginx/conf/php-rediscache.conf;
    }
    
      include /usr/local/nginx/conf/wpincludes/domain.com/wpsecure_domain.com.conf;
      include /usr/local/nginx/conf/php-wpsc.conf;
    
      # https://community.centminmod.com/posts/18828/
      #include /usr/local/nginx/conf/php-rediscache.conf;
      include /usr/local/nginx/conf/pre-staticfiles-local-domain.com.conf;
      include /usr/local/nginx/conf/pre-staticfiles-global.conf;
      include /usr/local/nginx/conf/staticfiles.conf;
      include /usr/local/nginx/conf/drop.conf;
      #include /usr/local/nginx/conf/errorpage.conf;
      include /usr/local/nginx/conf/vts_server.conf;
    }
    CURL output:
    Code:
    [06:41][root@hostname.domain.com ~]# curl -I http://domain.com
    HTTP/1.1 302 Moved Temporarily
    Date: Wed, 12 Feb 2020 06:43:27 GMT
    Content-Type: text/html
    Connection: keep-alive
    Set-Cookie: __cfduid=d4dc41858fed057f15721aa18959319501581489807; expires=Fri, 13-Mar-20 06:43:27 GMT; path=/; domain=.domain.com; HttpOnly; SameSite=Lax
    Location: https://www.domain.com/
    X-Powered-By: centminmod
    CF-Cache-Status: BYPASS
    Server: cloudflare
    CF-RAY: 563c969f097fe7d5-LAX
    
    [06:43][root@hostname.domain.com ~]# curl -I http://www.domain.com
    HTTP/1.1 302 Moved Temporarily
    Date: Wed, 12 Feb 2020 06:46:07 GMT
    Content-Type: text/html
    Connection: keep-alive
    Set-Cookie: __cfduid=d9a7490d4457d1b6efba91efd4b7df5771581489967; expires=Fri, 13-Mar-20 06:46:07 GMT; path=/; domain=.domain.com; HttpOnly; SameSite=Lax
    Location: https://www.domain.com/
    X-Powered-By: centminmod
    CF-Cache-Status: BYPASS
    Server: cloudflare
    CF-RAY: 563c9a89fc04792e-LAX
    
    [06:46][root@hostname.domain.com ~]# curl -I https://www.domain.com
    HTTP/1.1 301 Moved Permanently
    Date: Wed, 12 Feb 2020 06:50:44 GMT
    Content-Type: text/html; charset=UTF-8
    Connection: keep-alive
    Set-Cookie: __cfduid=d4707c70d869d1bf45722dab632ce60c31581490243; expires=Fri, 13-Mar-20 06:50:43 GMT; path=/; domain=.domain.com; HttpOnly; SameSite=Lax
    X-Redirect-By: WordPress
    Location: https://domain.com/
    X-Powered-By: centminmod
    X-Xss-Protection: 1; mode=block
    X-Content-Type-Options: nosniff
    X-Page-Speed: 1.13.35.2-0
    Cache-Control: max-age=0, no-cache
    CF-Cache-Status: DYNAMIC
    Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
    Server: cloudflare
    CF-RAY: 563ca1484dbfe7dd-LAX
    
    [06:50][root@hostname.domain.com ~]# curl -I https://domain.com
    HTTP/1.1 302 Moved Temporarily
    Date: Wed, 12 Feb 2020 06:53:14 GMT
    Content-Type: text/html
    Connection: keep-alive
    Set-Cookie: __cfduid=dea4bee1e63436bd6bb956ec6d354471f1581490394; expires=Fri, 13-Mar-20 06:53:14 GMT; path=/; domain=.domain.com; HttpOnly; SameSite=Lax
    Location: https://www.domain.com/
    X-Powered-By: centminmod
    CF-Cache-Status: DYNAMIC
    Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
    Server: cloudflare
    CF-RAY: 563ca4f5af4aeb89-LAX
    
    
    I am using Cloudflare and SSL is set to FULL and "Always HTTPS" option is set to OFF.
     
  6. pheonis

    pheonis Member

    62
    3
    8
    Dec 21, 2018
    Ratings:
    +4
    Local Time:
    7:22 AM
    Hi @eva2000 , I am still stuck. I don't understand where the error is. Can you please help here.
     
  7. pheonis

    pheonis Member

    62
    3
    8
    Dec 21, 2018
    Ratings:
    +4
    Local Time:
    7:22 AM
    Hi @eva2000 . I think its a bug in centmin. I hope you check and update it. Please address it.