Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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!

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

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.

share|improve this answer
add comment

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!

share|improve this answer
    
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? –  Roman Prykhodchenko Aug 18 '10 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 '10 at 14:38
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.