A
A
Andrey Kantser2017-08-16 21:07:20
Network administration
Andrey Kantser, 2017-08-16 21:07:20

How to create a subdomain of the third sublevel in Apache2?

Hello.
The situation is this. There is a server with a dedicated IP. (Conventionally 213.хх.хх.хх) It is running Linux OS (Ubuntu 16.04). Apache2 is installed under it. I registered a second-level domain name in the freenom service. (Conditionally mysite.tk). Everything works fine. I want to make a third level domain. cloud.mysite.tk for example. In the freenom service, I found the Register glue records option and entered "cloud" there. And then I really don't understand how to do it. Googled for about a day and got completely confused .__.
There is a file /etc/hosts

127.0.0.1       localhost
127.0.1.1       mysite.tk
127.0.1.1       cloud.mysite.tk

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

/etc/apache2/apache2.conf file
Mutex file:${APACHE_LOCK_DIR} default
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
LogLevel warn
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf
<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>
<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>
<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>
AccessFileName .htaccess
<FilesMatch "^\.ht">
        Require all denied
</FilesMatch>
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf

The /etc/apache2/ports.conf file
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf
Listen 80
<IfModule ssl_module>
        Listen 443
</IfModule>
<IfModule mod_gnutls.c>
        Listen 443
</IfModule>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

The /etc/apache2/sites-available/000-default.conf file
VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        #Redirect http://  https://
        ServerAdmin [email protected]
        DocumentRoot /var/www/html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

The /etc/apache2/sites-available/something.conf file
Alias /something "/var/www/something/"
<Directory /var/www/something/>
    Options +FollowSymlinks
    AllowOverride All
    <IfModule mod_dav.c>
        Dav off
    </IfModule>
    SetEnv HOME /var/www/something
    SetEnv HTTP_HOME /var/www/something
</Directory>

How it works: I go to the site mysite.tk. There I have a page and all sorts of links on it. You can go to mysite.tk/something and it will work.
How I want. I go to the site mysite.tk. There I have a page and all sorts of links on it. You can go to something.mysite.tk and it will work.
From googling, I realized that you need to leave only one large host that will listen on port 80 and catch requests. Then look at the http headers (which sounds strange to me) and redirect to the desired domain. With DNS servers, as I understand it, you don’t really need to mess around, because everything is configured in freenom.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2017-08-16
@Sanasol

.tk domains generally don't sell well.
they all work through an iframe or something else through the ass. Although this usually applies to free .tk.
I don't even remember if they were sold.
In short, take a normal domain to start with, which works as usual.
And here is your file /etc/hosts I'm even afraid to ask.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question