Welcome to Centmin Mod Community
Become a Member

subdomains to point to a folder under main domain

Discussion in 'Domains, DNS, Email & SSL Certificates' started by dandumit, Feb 3, 2021.

  1. dandumit

    dandumit New Member

    19
    1
    3
    Jan 9, 2021
    Ratings:
    +1
    Local Time:
    12:55 PM
    DEar All,
    I need to create 3 subdomains called cdn1.domain.com cdn3.domain.com cdn3.domain.com

    and all of those to point to a folder under domain.com for serving static content images :
    /home/nginx/domains/domain.com/public/img/

    How do I do this ?

    Do I have to create a new file like :
    /usr/local/nginx/conf/conf.d/cdn.domain.com.conf

    and to have there
    Code:
    server {
    server_name cdn1.abc.com cdn2.abc.com cdn3.abc.com;
    
    with path to subfolder


     
  2. eva2000

    eva2000 Administrator Staff Member

    46,650
    10,590
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +16,435
    Local Time:
    7:55 PM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    does domain.com vhost at /home/nginx/domains/domain.com/public/img/ already exist ?
     
  3. dandumit

    dandumit New Member

    19
    1
    3
    Jan 9, 2021
    Ratings:
    +1
    Local Time:
    12:55 PM
    folder /home/nginx/domains/domain.com/public/img/ exists and was created by application that resides on vhost "domanin.com"
    I need to create 3 fake subdomains cdn1.domain.com cdn3.domain.com cdn3.domain.com that will have home folder on
    /home/nginx/domains/domain.com/public/img/

    thank you,
    Daniel
     
  4. eva2000

    eva2000 Administrator Staff Member

    46,650
    10,590
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +16,435
    Local Time:
    7:55 PM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    Easiest way it to create a new Nginx vhost with those 3 subdomains via below custom steps and then edit that vhost's root to point to /home/nginx/domains/domain.com/public/img/ using Manual Method #1

    You currently can't automate parking one HTTPS SSL cert enabled domain (yourparkeddomain.com) on top of another HTTPS SSL cert enabled domain (domain.com) as you need for each domain to have it's own SSL certificate reference and Centmin Mod 123.09beta01 can only do one domain Letsencrypt SSL certificate issuance per centmin.sh menu option 2, 22 or nv command runs. See below instructions for Parked HTTPS SSL Domains.

    Parked HTTPS SSL Domains



    Parked domains meaning different domains and/or subdomains all point to same IP address and site content when accessed in a web browser. These methods outlined below are NOT for multiple domains pointing to different site/content.

    As there's no way to automate such you have 2 manual methods available

    Manual Method 1 - Do manual Nginx vhost creation via the underlying acme.sh client. If you have not yet created any of the intended domains/nginx vhosts, you can use addons/acmetool.sh directly via SANS Multi-Domain SSL Certificates method. Otherwise, if some or all intended domains/nginx vhosts have already been created then use manual method as discussed in steps in this post here and here.

    Manual Method 2 - create a domain Nginx HTTPS vhost site for each domain.

    It would be a manual process which involves creating the parked domain's own Nginx HTTPS SSL cert enabled vhost via centmin.sh menu option 2 or nv command and setting it up with valid working DNS A records for domain's www and non-www versions if main domain or DNS A for subdomain and ensure it's working and select letsencrypt option with live default HTTPS SSL cert and then editing it's nginx config file at /usr/local/nginx/conf/conf.d/yourparkeddomain.com.ssl.conf and then just changing root path to your origin domain's root

    in /usr/local/nginx/conf/conf.d/yourparkeddomain.com.ssl.conf change it's default public web root path from
    Code (Text):
    root /home/nginx/domains/yourparkeddomain.com/public

    to
    Code (Text):
    root /home/nginx/domains/domain.com/public

    which now matches the public web root for domain.com nginx vhost listed in domain.com nginx vhost config file at /usr/local/nginx/conf/conf.d/domain.com.ssl.conf

    now both yourparkeddomain.com and domain.com public web root paths point to /home/nginx/domains/domain.com/public so access via the domains will serve files located in /home/nginx/domains/domain.com/public. It does mean that any configurations you manually setup in /usr/local/nginx/conf/conf.d/domain.com.ssl.conf need to be replicated in /usr/local/nginx/conf/conf.d/yourparkeddomain.com.ssl.conf.

    you can use common include file templates you set to make it easier i.e. if in both /usr/local/nginx/conf/conf.d/yourparkeddomain.com.ssl.conf and /usr/local/nginx/conf/conf.d/domain.com.ssl.conf you have a custom location content like
    Code (Text):
    location /test {
      include /usr/local/nginx/conf/php.conf;
      try_files $uri $uri/ /index.php
    }

    you could place that location /test context into a custom template file you create at /home/nginx/domains/domain.com/common_includes.conf and reference it in both /usr/local/nginx/conf/conf.d/yourparkeddomain.com.ssl.conf and /usr/local/nginx/conf/conf.d/domain.com.ssl.conf as
    Code (Text):
    include /home/nginx/domains/domain.com/common_includes.conf;

    Final note in origin domain's nginx vhost at /usr/local/nginx/conf/conf.d/domain.com.ssl.conf also add canonical header to ensure search engines visiting domain.com know content is originally at domain.com to prevent search engines from flagging yourparkeddomain.com content as duplicated content.
    Code (Text):
    add_header Link "<http://domain.com$request_uri>; rel=\"canonical\"";
    

    i.e. placing the header just below existing add_header entries in default nginx vhost config for HTTPS SSL domains
    Code (Text):
      # 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 Link "<http://domain.com$request_uri>; rel=\"canonical\"";
    

    then restart nginx and php-fpm services
    Code (Text):
    nprestart

    To confirm just run curl command in SSH against your domain i.e. curl headers and grep filter for word canonical
    Code (Text):
    curl -sI https://domain.com | grep canonical
    

    output would be something like
    Code (Text):
    curl -sI https://domain.com | grep canonical
    Link: <http://domain.com/>; rel="canonical"