DEV Community

loading...
Cover image for Map Subdomain with Web Application

Map Subdomain with Web Application

Chandresh Singh
Creator of ReportBugz.com
・2 min read

For mapping subdomain with Web app we need to creating DNS entry through Domain Service Provider account for linking subdomain and server and then we need to create a virtual host configuration for telling web server to direct all requests on subdomain to our web app.

If you would like to watch me doing that then you can watch it here as well.

Let's first start with creating a virtual host on apache.

For that, SSH on your Server.

Make sure you have root access. Switch to root user.

sudo su root

Go to apache site configurations directory

cd /etc/apache2/sites-available

Create a new configuration file for your site.

nano app.example.com.conf

Configure virtual host like this. Make sure that the path in document root and directory should be the path of your web app directory containing index file.

<VirtualHost *:80>
        ServerAdmin admin@example.com
        ServerName  app.example.com
        ServerAlias www.app.example.com
        DocumentRoot /var/www/example_app

        ErrorLog ${APACHE_LOG_DIR}/app.example.com-error.log
        CustomLog ${APACHE_LOG_DIR}/app.example.com-access.log combined

        <Directory /var/www/example_app/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
                Require all granted
        </Directory>
</VirtualHost>

Save the file.

Enable site configuration.

a2ensite app.example.com.conf

Reload web server.

service reload apache2

Go to your domain service provider.

Open DNS Settings page.

DNS Settings

Add a new A type Record with your subdomain and IP address of your server.

New A type Record

Wait for some time. Usually it gets live within few hours but depending upon your domain service provider, it may take unto 48 hours.

That’s it!

You can now access your web app using your subdomain.

Discussion (0)

Forem Open with the Forem app