1

Using nginx and php I need to create multiple sub domain in local host. How i can make it happen?

I am using ubuntu 12.04 and php5 withnginx as webserver.

i Have tried *.servername.com in my configuration file. BUt it is not working.

1 Answers1

2

In localhost you can make entry of subdomain in "hosts" file at dir of C:\Windows\System32\Drivers\etc (it may be at /etc of linux)

127.0.0.1       maindomain.com
127.0.0.1       one.maindomain.com
127.0.0.1       two.maindomain.com

After that you have to make entry in httpd.conf file

<VirtualHost 127.0.0.1:80>

DocumentRoot pathToMainDomain
ServerName maindomain.com
</VirtualHost>



<VirtualHost 127.0.0.1:80>

DocumentRoot pathToMainDomain

ServerName one.maindomain.com
</VirtualHost>



<VirtualHost 127.0.0.1:80>

DocumentRoot pathToMainDomain
ServerName two.maindomain.com
</VirtualHost>
Prashant M Bhavsar
  • 1,136
  • 9
  • 13
  • hi @prashant M thanks alot for your reply. I this is to create multiple virtual hosts. But in my casse it is not the exact thing which I am looking for. `Dynamically creating sub domain` that is what i needed. Anyways **thanks alot.** – thomas chacko Dec 08 '14 at 07:01
  • Always welcome..i will check with Dynamically creating sub domain and update you..Thanks – Prashant M Bhavsar Dec 08 '14 at 07:02
  • hope to hear from u soon. – thomas chacko Dec 08 '14 at 07:08
  • Please check with this post i have found related to your query..it may help you.. http://stackoverflow.com/questions/5822117/how-to-dynamically-create-subdomains http://stackoverflow.com/questions/183928/how-to-let-php-to-create-subdomain-automatically-for-each-user – Prashant M Bhavsar Dec 08 '14 at 07:15
  • i am trying to find exact and clear solution for your query..will keep you update on same. – Prashant M Bhavsar Dec 08 '14 at 07:16
  • if you want I can clarify my question. say a user signed up in my site(`example.com`) and creates a micro site as he wishes say `user1` is his name then the micro site name would created as `user1.example.com` and it should happen dynamically. Since creating virtual host again and again is not practical, I am following this way. please help – thomas chacko Dec 08 '14 at 10:31