These are the steps I took to setup multiple hosts for Nginx on a 256MB Slicehost VPS running Gentoo Linux. They should work in other similar Linux environments. YMMV.
I followed this multiple hosts layout intended for a single admin/user, and adapted for Nginx this virtual host permissions setup written for Apache.
Place your user account in the web server (Nginx) group:
sudo usermod -a -G nginx myuserLogout, login again, check if you are in the “nginx” group by typing:
groupsCreate the “public_html” or “htdocs” or whatever directory that will hold all your websites:
mkdir /home/myuser/public_htmlCreate a directory for your “default” or “catch-all” website:
mkdir /home/myuser/public_html/defaultMake sure the “public_html” directory is owned by your user and belongs to the web server group:
sudo chgrp -R nginx /home/myuser/public_html
Make any files and directories created in the future under “public_html” inherit the same ownership and permissions, so you don’t have to set these permissions again:
sudo chmod -R 2750 /home/myuser/public_html
Edit Nginx’s config file:
sudo nano /etc/nginx/nginx.conf
Modify the “server” section to look something like this: (source)
server { listen 80 default; server_name _ *; access_log /var/log/nginx/localhost.access_log main; error_log /var/log/nginx/localhost.error_log info; location / { index index.html,index.htm,index.php; root /home/myuser/public_html/default; } location ~ .*.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:1026; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /home/myuser/public_html/default/$fastcgi_script_name; } }
Start Nginx:
sudo /etc/init.d/nginx startSet Nginx to automatically start on bootup:
sudo rc-config add nginxAnd you’re done! If you need to add another website in the future, simply add another “server” section to nginx.conf.
If you liked this post, please subscribe to my feed. Thanks for visiting!

