At home and at work, I use a combination of Bind9 and Nginx to solve this problem. This requires some configuration, but after that you will no longer have to touch the nginx configuration file. I have added some restrictions below.
Customization
Setting up a DNS server, (Bind9, dnsmasq)
1) Set up a local DNS server and create a node called DEV 2) Create a name record in DEV for
* A 127.0.0.1
And restart the DNS server. 3) Make sure you can dig * .dev and make sure you return to 127.0.0.1.
Configure Nginx
1) In your nginx.conf or wherever you store your conf.d stuff, create a vHost entry that looks something like this: you can adapt it to your needs.
server { listen 80; server_name *.dev; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; if ($host ~* ^(.*).dev$) { set $site $1; } if (!-d /var/www/$site/) { return 404; } location ~ index.php$ { fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_pass backend; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/$site/$fastcgi_script_name; include fastcgi_params; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_intercept_errors on; fastcgi_ignore_client_abort off; fastcgi_connect_timeout 60; fastcgi_send_timeout 180; fastcgi_read_timeout 180; fastcgi_buffer_size 128k; fastcgi_buffers 4 256k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; } location ~ / { try_files $uri $uri/ /index.php?$args; } }
2) Restart the nginx service.
3) Profit
Once this is set up, to create a new site all you have to do is create a new folder in / var / www / .
mkdir -p /var/www/sitename/
This site and the PHP under it can be accessed through sitename.dev.
As mentioned earlier, there are some limitations to this. sitename must be all lowercase and contain spaces or special characters (including periods). Secondly, it really only works for sites downloaded via index.php.
If you have radically different site structures, you can change a few things to give you a more reliable setting. For example, you can write your configuration so that it looks something like this.
server { listen 80; server_name *.*.dev; [...] if ($host ~* ^(.*).(.*).dev$) { set $site $1; set $folder $2; } if (!-d /var/www/$folder/$site/) { return 404; } [...] fastcgi_param SCRIPT_FILENAME /var/www/$folder/$site/$fastcgi_script_name; [...] }
And suppose you upgraded your DNS server to answer..dev, then you can write our directories as follows to give you an idea.
/var/www/wordpress/site1 /var/www/wordpress/site2 /var/www/wordpress/site3 /var/www/zend/site1 /var/www/zend/site2 /var/www/zend/site3
As I said, I use this setting at home and when working with +15 people. Our setup of work is a little more complicated (a common server, each has its own home folder), but it works fine. Personally, I prefer working on subdomains rather than localhost paths.
Hope this helps!