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 andphp5 withnginx as webserver.

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

let me clarify little more

say a user signed up in my site(example.com) and creates a micro site in any name as he wishes (provided that name should be available) say user1 is his name and he want to create a micro site as user1.example.com and it should happen dynamically. Since creating virtual host again and again is not practical, please help

  • possible duplicate of [Wildcard DNS and subdomains](http://serverfault.com/questions/12124/wildcard-dns-and-subdomains) – AD7six Dec 08 '14 at 11:31
  • thanks alot. I am toatally new to this thing. **Thanks alot for your prominent reply.** other prob with me is that I 'm doing it in local host – thomas chacko Dec 08 '14 at 11:36

1 Answers1

1

Given that the crux of your question is basically related to accessing newly created sites from users of your site which is designed to allow this, you would indeed need to create virtual hosts for every site created (as otherwise your web server would have no way to determine which site to process requests for).

You could look at automatically creating vhosts based on a template and reloading the nginx config, but I wouldn't recommend it - I generally find that this level of automation is undesirable and that you should really be taking care of individual site configs on a per-user basis.

You would also need to create an appropriate wildcard CNAME record as per this article in your DNS.

Edit: as per the comments below, here is a suggestion as to what you could potentially implement.

You could, for example, have a template virtual host file, containing something similar to the following:

server {
        listen 80;
        listen 443 ssl;

        server_name  template.yourdomain.com;

        access_log      /var/log/nginx/template.yourdomain.com_access.log main;
        error_log       /var/log/nginx/template.yourdomain.com_error.log warn;

}

Which you could then replicate altering the 'template' entries with the subdomain of the user's choice. It depends on the rest of your environment, but for example you could have a text field to allow them to input the desired subdomain, then have the 'submit' (or similar) action trigger a script you've created to alter the above config file for an appropriate one for them, copying it to theirdomain.yourdomain.com.conf and then running service nginx reload.

This is just a vague idea of what you would need to do - the specifics are up to you based on your environment and requirements.

As I have already said, however, you should consider the implications of implementing this.

BE77Y
  • 2,577
  • 3
  • 17
  • 23
  • thanks for your rreply. But client demands that.. – thomas chacko Dec 08 '14 at 11:47
  • Well, I'm afraid that whether or not they demand it does not change whether or not it is feasible! You could allow the automatic creation of configuration files which would then be included by an automatic reloading of nginx configuration, but as I say - I would not recommend this. While it is technically possible, it would allow an undesirable level of potential access to the server (or require an undesirable amount of elevated privilege to execute, more accurately). What I'm saying is that you should potentially rethink your goals. – BE77Y Dec 08 '14 at 12:07
  • can you help me in creating the same in local host??? after that i'll come to a conclusion. thanks in addvance – thomas chacko Dec 08 '14 at 12:18
  • I've added extra information above in my post. – BE77Y Dec 08 '14 at 12:35