Join the community today
Become a Member

Nginx Domains Multiple domains setup

Discussion in 'Install & Upgrades or Pre-Install Questions' started by Altair, May 25, 2020.

  1. Altair

    Altair Member

    68
    3
    8
    Jan 27, 2018
    Ratings:
    +3
    Local Time:
    10:41 AM
    I have centos 7 and latest centmin mod installed, I created first vhost via cetmin menu, then after a month I'm creating another website on same server, so I just created a new vhost via cetmin menu, and I'm using cloudflare for dns and pointed 2nd domain to server ip.

    however, when I uploaded site files to public/ directory of my new domain, I browsed the website and I'm getting:

    Centmin Mod Nginx Test Page

    even though I deleted the default index, also nginx vhost is configured right as it points
    root /home/nginx/domains/example.com/public;


    I even downloaded index.html from public and it's the new index, but accessing the site I just get centmin mod nginx test page

    why this is happening
     
  2. Jon Snow

    Jon Snow Active Member

    917
    188
    43
    Jun 30, 2017
    Ratings:
    +293
    Local Time:
    4:41 AM
    Nginx 1.13.9
    MariaDB 10.1.31
    Run this command and see what happens:
    Code (Text):
    nprestart

    Sometimes when I delete the files, they remain until I restart nginx.

    Also, make sure you're using the right version of your site (http/https/www/non-www).

    You might want to post your nginx vhost config file for others to take a look at.
     
  3. Altair

    Altair Member

    68
    3
    8
    Jan 27, 2018
    Ratings:
    +3
    Local Time:
    10:41 AM
    tried that didn't work

    vhost file is just the default created for what domain I entered when creating vhost in centmin sh menu
     
  4. Altair

    Altair Member

    68
    3
    8
    Jan 27, 2018
    Ratings:
    +3
    Local Time:
    10:41 AM
    any assistance?
     
  5. eva2000

    eva2000 Administrator Staff Member

    58,894
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    5:41 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    Is the 2nd domain created with Letsencrypt SSL and default to HTTPS with non-HTTPS to HTTPS redirect ? If so ensure Cloudflare is using Full SSL and not Flexible SSL so Cloudflare can speak to HTTPS Nginx origin backend server.
     
  6. Altair

    Altair Member

    68
    3
    8
    Jan 27, 2018
    Ratings:
    +3
    Local Time:
    10:41 AM
    I'm using cloudflare dns only, also I didn't create ssl certificate so I'm using the vhost for http only
     
  7. eva2000

    eva2000 Administrator Staff Member

    58,894
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    5:41 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    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)

    what is output of these commands in ssh
    Code (Text):
    curl -I https://domain.com
    

    Code (Text):
    curl -I https://www.domain.com
    

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

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

    wrap output in CODE tags
     
  8. Altair

    Altair Member

    68
    3
    8
    Jan 27, 2018
    Ratings:
    +3
    Local Time:
    10:41 AM

    /usr/local/nginx/conf/conf.d/newdomain.com.conf
    Code (Text):
    # 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 REDACTED.com;
    #            return 301 $scheme://www.REDACTED.com$request_uri;
    #       }
    
    server {
    
      server_name REDACTED.com www.REDACTED.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/REDACTED.com/log/access.log combined buffer=256k flush=5m;
      error_log /home/nginx/domains/REDACTED.com/log/error.log;
    
      include /usr/local/nginx/conf/autoprotect/REDACTED.com/autoprotect-REDACTED.com.conf;
      root /home/nginx/domains/REDACTED.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;
    
      location / {
      include /usr/local/nginx/conf/503include-only.conf;
    
    # 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;
    
      }
    


    /usr/local/nginx/conf/conf.d/newdomain.com.ssl.conf
    is EMPTY!

    Code (Text):
    curl -I https://domain.com
    HTTP/1.1 200 OK
    Date: Tue, 26 May 2020 04:21:00 GMT
    Content-Type: text/html; charset=utf-8
    Content-Length: 4515
    Last-Modified: Fri, 27 Mar 2020 02:22:42 GMT
    Connection: keep-alive
    Vary: Accept-Encoding
    ETag: "5e7d6372-11a3"
    Server: nginx centminmod
    X-Powered-By: centminmod
    Accept-Ranges: bytes
    


    Code (Text):
    curl -I https://www.domain.com
    curl: (7) Failed connect to www.domain.com:443; Connection refused
    


    Code (Text):
    curl -I http://domain.com
    HTTP/1.1 200 OK
    Date: Tue, 26 May 2020 04:24:19 GMT
    Content-Type: text/html; charset=utf-8
    Content-Length: 4515
    Last-Modified: Fri, 27 Mar 2020 02:22:42 GMT
    Connection: keep-alive
    Vary: Accept-Encoding
    ETag: "5e7d6372-11a3"
    Server: nginx centminmod
    X-Powered-By: centminmod
    Accept-Ranges: bytes
    
    

    Code (Text):
    curl -I http://www.domain.com
    
    HTTP/1.1 200 OK
    Date: Tue, 26 May 2020 04:24:37 GMT
    Content-Type: text/html; charset=utf-8
    Content-Length: 4515
    Last-Modified: Fri, 27 Mar 2020 02:22:42 GMT
    Connection: keep-alive
    Vary: Accept-Encoding
    ETag: "5e7d6372-11a3"
    Server: nginx centminmod
    X-Powered-By: centminmod
    Accept-Ranges: bytes
    
    You have new mail in /var/spool/mail/root
    
    
     
  9. eva2000

    eva2000 Administrator Staff Member

    58,894
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    5:41 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    the non-www HTTPS version of your site is resolving to curl header checks
    Code (Text):
    curl -I https://domain.com
    HTTP/1.1 200 OK
    Date: Tue, 26 May 2020 04:21:00 GMT
    Content-Type: text/html; charset=utf-8
    Content-Length: 4515
    Last-Modified: Fri, 27 Mar 2020 02:22:42 GMT
    Connection: keep-alive
    Vary: Accept-Encoding
    ETag: "5e7d6372-11a3"
    Server: nginx centminmod
    X-Powered-By: centminmod
    Accept-Ranges: bytes
    

    while www HTTPS version of your site is correctly refusing connection when HTTPS isn't enabled
    what is output for more verbose
    Code (Text):
    curl -Ivk https://domain.com
    

    and
    Code (Text):
    curl -Ivk https://www.domain.com
    

    That should also show the SSL certificate being incorrectly served on non-www HTTPS when it shouldn't be.
     
  10. Altair

    Altair Member

    68
    3
    8
    Jan 27, 2018
    Ratings:
    +3
    Local Time:
    10:41 AM
    here are the results:

    Code (Text):
    curl -Ivk https://domain.com
    
    * About to connect() to domain.com port 443 (#0)
    *   Trying serverIP...
    * Connection refused
    * Failed connect to domain.com:443; Connection refused
    * Closing connection 0
    curl: (7) Failed connect to domain.com:443; Connection refused
    


    Code (Text):
    curl -Ivk https://www.domain.com
    
    
    * About to connect() to www.domain.com port 443 (#0)
    *   Trying serverIP...
    * Connection refused
    * Failed connect to www.domain.com:443; Connection refused
    * Closing connection 0
    curl: (7) Failed connect to www.domain.com:443; Connection refused
    
    


    so why do I get default centmin mod page? should I delete the site then re create it? also I uploaded through sftp root the files into domain /public directory.

    When creating the site, I only used centmin menu option, should I map the domain to server ip or something? this is 2nd domain and my hostname is correct on a 1st domain
     
    Last edited: May 27, 2020
  11. eva2000

    eva2000 Administrator Staff Member

    58,894
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    5:41 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    strange this time curl -I https://domain.com didn't work like it did before.

    When you install Centmin Mod it's setup a main hostname nginx vhost host for server which is where Nginx default install index page is shown. Accessing server via IP address will show that page and it's correct and should be left as is as the main hostname site is also used for statistics pages outlined here. When you create a new Nginx vhost site via centmin.sh menu option 2, 22 or nv commands, you have a separate Nginx vhost directory structure. The differences are outlined on official Config file page and at Getting Started Guide step 1 and bottom of that page here.
    If your site domain name when visited redirects to main hostname and default nginx index page, then that is usually due to the main hostname being same as the site domain name which is incorrect as they need to differ.

    What does your /usr/local/nginx/conf/conf.d/virtual.conf and /usr/local/nginx/conf/conf.d/yourdomain.com.conf contents look like ? Make sure virtual.conf main hostname's server_name isn't same as any added nginx vhost site's domain name as per Getting Started Guide step 1, the main hostname needs to be unique.

    You can check via recursive grep filter of your domain name in vhost directory at /usr/local/nginx/conf/conf.d
    Code (Text):
    grep -rnw 'yourdomain.com' /usr/local/nginx/conf/conf.d
    

    Also check DNS is correct use dig to check DNS for domain
    Code (Text):
    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
    

    check HTTP headers via curl for both HTTP (and HTTPS if you have HTTPS/SSL)
    Code (Text):
    curl -I http://yourdomain.com
    curl -I http://www.yourdomain.com
    curl -I https://yourdomain.com
    curl -I https://www.yourdomain.com
    curl -I http://hostname.yourdomain.com
    
     
  12. Altair

    Altair Member

    68
    3
    8
    Jan 27, 2018
    Ratings:
    +3
    Local Time:
    10:41 AM
    contents of /usr/local/nginx/conf/conf.d/virtual.conf
    Code (Text):
    
    
    server {
                listen 80 default_server backlog=4095 reuseport;
                server_name li15x0-xxx.members.linode.com;
                root   html;
    
            access_log              /var/log/nginx/localhost.access.log     combined buffer=256k flush=5m;
            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;
    
           }
    
    


    contents of /usr/local/nginx/conf/conf.d/yourdomain.com.conf
    Code (Text):
    # 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 REDACTED.com;
    #            return 301 $scheme://www.REDACTED.com$request_uri;
    #       }
    
    server {
    
      server_name REDACTED.com www.REDACTED.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/REDACTED.com/log/access.log combined buffer=256k flush=5m;
      error_log /home/nginx/domains/REDACTED.com/log/error.log;
    
      include /usr/local/nginx/conf/autoprotect/REDACTED.com/autoprotect-REDACTED.com.conf;
      root /home/nginx/domains/REDACTED.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;
    
      location / {
      include /usr/local/nginx/conf/503include-only.conf;
    
    # 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;
    
      }
    
    



    Code (Text):
    grep -rnw 'yourdomain.com' /usr/local/nginx/conf/conf.d
    returns nothing
    


    Code (Text):
    dig +short A @8.8.8.8 yourdomain.com
    returns server ip
    dig +short A @8.8.8.8 www.yourdomain.com
    returns
    
    domain.com.
    server ip
    
    dig +short A @8.8.8.8 hostname.yourdomain.com
    returns nothing
    


    Code (Text):
    curl -I http://yourdomain.com
    HTTP/1.1 200 OK
    Date: Tue, 26 May 2020 20:10:57 GMT
    Content-Type: text/html; charset=utf-8
    Content-Length: 4515
    Last-Modified: Fri, 27 Mar 2020 02:22:42 GMT
    Connection: keep-alive
    Vary: Accept-Encoding
    ETag: "5e7d6372-11a3"
    Server: nginx centminmod
    X-Powered-By: centminmod
    Accept-Ranges: bytes
    


    Code (Text):
    curl -I http://www.yourdomain.com
    HTTP/1.1 200 OK
    Date: Tue, 26 May 2020 20:11:41 GMT
    Content-Type: text/html; charset=utf-8
    Content-Length: 4515
    Last-Modified: Fri, 27 Mar 2020 02:22:42 GMT
    Connection: keep-alive
    Vary: Accept-Encoding
    ETag: "5e7d6372-11a3"
    Server: nginx centminmod
    X-Powered-By: centminmod
    Accept-Ranges: bytes
    


    Code (Text):
    curl -I https://yourdomain.com
    curl: (7) Failed connect to yourdomain.com:443; Connection refused


    Code (Text):
    curl -I https://www.yourdomain.com
    curl: (7) Failed connect to www.yourdomain.com:443; Connection refused
    


    Code (Text):
    curl -I http://hostname.yourdomain.com
    HTTP/1.1 200 OK
    Date: Tue, 26 May 2020 20:13:35 GMT
    Content-Type: text/html; charset=utf-8
    Content-Length: 4515
    Last-Modified: Tue, 05 May 2020 13:12:38 GMT
    Connection: keep-alive
    Vary: Accept-Encoding
    ETag: "5eb16646-11a3"
    Server: nginx centminmod
    X-Powered-By: centminmod
    Accept-Ranges: bytes
    
    
     
  13. eva2000

    eva2000 Administrator Staff Member

    58,894
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    5:41 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    That should return an entry for /usr/local/nginx/conf/conf.d/yourdomain.com.conf file contents matches for your yourdomain.com keyword.

    example
    Code (Text):
    grep -rnw 'demodomain.com' /usr/local/nginx/conf/conf.d             
    /usr/local/nginx/conf/conf.d/demodomain.com.conf:5:            server_name demodomain.com;
    /usr/local/nginx/conf/conf.d/demodomain.com.conf:6:            return 301 $scheme://www.demodomain.com$request_uri;
    /usr/local/nginx/conf/conf.d/demodomain.com.conf:12:            server_name www.demodomain.com;
    /usr/local/nginx/conf/conf.d/demodomain.com.conf:17:            access_log /home/nginx/domains/demodomain.com/log/access.log ;
    /usr/local/nginx/conf/conf.d/demodomain.com.conf:18:            error_log /home/nginx/domains/demodomain.com/log/error.log error;
    /usr/local/nginx/conf/conf.d/demodomain.com.conf:20:            root   /home/nginx/domains/demodomain.com/public;
    


    If yours is returning empty then your /usr/local/nginx/conf/conf.d/yourdomain.com.conf isn't registering in Nginx - it's server_name listing is what tells Nginx to direct yourdomain.com listed in server_name to the correct Nginx site web root.

    what is output for
    Code (Text):
    ls -lah /usr/local/nginx/conf/conf.d | grep yourdomain
    

    example
    Code (Text):
    ls -lah /usr/local/nginx/conf/conf.d | grep demodomain
    -rw-r--r--  1 root root 1.1K May  6 05:21 demodomain.com.conf
    
     
  14. Altair

    Altair Member

    68
    3
    8
    Jan 27, 2018
    Ratings:
    +3
    Local Time:
    10:41 AM
    I'm sorry but it does return something when I tried it again:

    Code (Text):
    [07:26][root@hostname.domain.com ~]# grep -rnw 'redacted.com' /usr/local/nginx/conf/conf.d
    /usr/local/nginx/conf/conf.d/redacted.com.conf:9:#            server_name redacted.com;
    /usr/local/nginx/conf/conf.d/redacted.com.conf:10:#            return 301 $scheme://www.redacted.com$request_uri;
    /usr/local/nginx/conf/conf.d/redacted.com.conf:15:  server_name redacted.com www.redacted.com;
    /usr/local/nginx/conf/conf.d/redacted.com.conf:31:  access_log /home/nginx/domains/redacted.com/log/access.log combined buffer=256k flush=5m;
    /usr/local/nginx/conf/conf.d/redacted.com.conf:32:  error_log /home/nginx/domains/redacted.com/log/error.log;
    /usr/local/nginx/conf/conf.d/redacted.com.conf:34:  include /usr/local/nginx/conf/autoprotect/redacted.com/autoprotect-redacted.com.conf;
    /usr/local/nginx/conf/conf.d/redacted.com.conf:35:  root /home/nginx/domains/redacted.com/public;
    


    Code (Text):
    [07:26][root@hostname.domain.com ~]# ls -lah /usr/local/nginx/conf/conf.d | grep redacted.com
    -rw-r--r--. 1 root root 2.2K May 24 17:41 redacted.com.conf
    You have new mail in /var/spool/mail/root
    
     
  15. eva2000

    eva2000 Administrator Staff Member

    58,894
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    5:41 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    That all looks correct, yourdomain.com with DNS A records for non-www and www pointing to server IP should when accessed via yourdomain.com should go to yourdomain.com.conf listed server_name yourdomain.com at web root defined by
    Code (Text):
    root /home/nginx/domains/REDACTED.com/public;

    Do you have more than 1 IP address added to your Centmin Mod server ? Have more than one Centmin Mod server on Linode ? Are you sure you didn't mistype the IP address for DNS record to a 2nd Centmin Mod server cause if it's a 2nd Centmin Mod server IP, because yourdomain.com.conf Nginx vhost won't exist on that server so access via yourdomain.com will go to 2nd Centmin Mod server's default main hostname Nginx test page instead.
     
  16. Altair

    Altair Member

    68
    3
    8
    Jan 27, 2018
    Ratings:
    +3
    Local Time:
    10:41 AM
    wow you just nailed it! I had mistakenly put the ip of another linode server I own in cloudflare dns only a record!
    Now I've put the correct ip and now everything works!

    thanks eva you're a smart person. Hope centmin mod get acquired by some high end company to make up for your efforts in centmin mod

    ps: when creating new site via centmin mod menu option 2: and then asks for FTP I entered user and password manually, but when trying to login via filezilla I mostly get connection refused, with host as the ip address of the server. any articles on ftp?
     
  17. eva2000

    eva2000 Administrator Staff Member

    58,894
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    5:41 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    haha - sometimes the issues are behind the keyboard :)
    Thanks for the kind words :D

    Sure you didn't enter the wrong IP into Filezilla's IP field ? :) ;)