Creating subdomains in Azure

Viewed 3967

We have a VM in Azure, ourserver.westeurope.cloudapp.azure.com. I need to create two subdomains, sub1.ourserver.westeurope.cloudapp.azure.com and sub2.ourserver.westeurope.cloudapp.azure.com. Both must point to the same IP as ourserver.westeurope.cloudapp.azure.com.

How do I do it?

3 Answers

I'm not sure, but MAYBE, the URL rewrite can work in this situation.

You can have different folders inside you VM's "public" folder, one for each content of the subdomain. Then, use the URL Rewrite to map each subdmain in their specific folder.

I did something similar, but wasn't for subdomains. I just pointed different domains to different folders. Here is an example of how it would be in your case (I didn't test, just guessed based on my case):

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="sub1 virtual path rewrite">
                    <match url="^.*$" ignoreCase="false" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^sub1\.ourserver\.westeurope\.cloudapp\.azure$" />
                    </conditions>
                    <action type="Rewrite" url="/Sub1Folder/{R:0}" appendQueryString="true" />
                </rule>
                <rule name="sub2 virtual path rewrite">
                    <match url="^.*$" ignoreCase="false" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^sub2\.ourserver\.westeurope\.cloudapp\.azure$" />
                    </conditions>
                    <action type="Rewrite" url="/Sub2Folder/{R:0}" appendQueryString="true" />
                </rule>
            </rules>
            <outboundRules>
                <rule name="sub1 virtual path rewrite">
                    <match serverVariable="RESPONSE_LOCATION" pattern="^(https?\://ourserver\.westeurope\.cloudapp\.azure)/Sub1Folder/(.+/)$" />
                    <conditions>
                        <add input="{RESPONSE_STATUS}" pattern="^301$" ignoreCase="false" />
                    </conditions>
                    <action type="Rewrite" value="sub1/{R:1}/{R:2}" />
                </rule>
                <rule name="sub2 virtual path rewrite">
                    <match serverVariable="RESPONSE_LOCATION" pattern="^(https?\://ourserver\.westeurope\.cloudapp\.azure)/Sub2Folder/(.+/)$" />
                    <conditions>
                        <add input="{RESPONSE_STATUS}" pattern="^301$" ignoreCase="false" />
                    </conditions>
                    <action type="Rewrite" value="sub2/{R:1}/{R:2}" />
                </rule>
            </outboundRules>
        </rewrite>
    </system.webServer>
</configuration>

I don't know if you will need to create subdomains in the domain register. Maybe you will need to, because sometimes you have to pay extra fees to have subdomains. So, I don't know if the URL Rewrite would work without creating them. And if it works, I don't know if it's legal to do (please don't do any workaround to avoid the register fees).

Related