0

I need to create and remove subdomains automatically using nginx. I know I can do it using the following approach:

server {
    listen 80;
    server_name example.com *.example.com;
    root /var/www/example.com/$subdomain;
    set $subdomain "";
    if ($host ~* ^([a-z0-9-\.]+)\.example.com$) {
        set $subdomain $1;
    }
    if ($host ~* ^www.example.com$) {
        set $subdomain "";
    }
}

I can create folders in root /var/www/example.com/ using a script and nginx will create appropriate subdomains for me.

However I need to set such parameters as number of simultaneous connections and maximum connection bandwidth and values of that parameters will be passed to my script.

So the question is how can I set those additional parameters?

If there's no way to solve my problem using nginx you can advice me how to solve it using apache.

Thanks!

3 Answers 3

1

I include a subfolder ( /etc/nginx/confs ) and create a new file for each subdomain. I'm running rails apps so I need a fair bit of configuration in each subdomain. I have a background beanstalkd worker that when someone signs up installs the application, creates the nginx conf and reloads nginx.

0

If I'm getting this right what you have now can be achieved with mod_vhost_alias on apache so you have the exact same behaviour as you have on nginx as per this manual page.

Concerning the rest of the parameters i'd recommend you use mod_qos and set them in .htaccess files in the directory where the files to be served live.

I'm available for questions if you comment on this post :)

Hope this helps!

2
  • Does nginx support such external configuration files where I can put my additional parameters? Will user be able to modify my limitations if I set those parameters in an .htaccess file or any other external configuration file supported by nginx? Aug 18, 2010 at 13:14
  • Hi again. Anyone with write access to .htaccess will be able to change anything you set there (obviously). About the .htaccess equivalent on nginx... to my knowledge there's no such thing but if you do find a solution for that i'd be interested in learning too :)
    – Khai
    Aug 18, 2010 at 14:38
0

There is no way to do exactly what you want. Nginx is not written with mass hosting in mind but rather written for high traffic sites.

The proper way to handle this with Nginx is to not have a catch-all server block but rather have a server block for each subdomain. Creating these by hand is obviously tedious so writing a script that will generate them is highly recommended and not too complicated.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .