Tag Archive for 'setup'

Setting up multiple hosts for Nginx (on a Gentoo VPS)

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 myuser

Logout, login again, check if you are in the “nginx” group by typing:

groups

Create the “public_html” or “htdocs” or whatever directory that will hold all your websites:

mkdir /home/myuser/public_html

Create a directory for your “default” or “catch-all” website:

mkdir /home/myuser/public_html/default

Make 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 start

Set Nginx to automatically start on bootup:

sudo rc-config add nginx

And 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!

Preparing Gentoo Linux for a minimalist web server

This is a first stab at a guide to preparing a minimalist web server running on Gentoo Linux, ideal for a small VPS. Don’t follow these instructions unless you know what you’re doing, ’cause I’m not sure I do. :P (Apologies for the lack of updates; I’ve been busy playing with this Gentoo web server amongst other things.)

This is a draft. Comments, suggestions, corrections, improvements are very much welcome!

Continue reading ‘Preparing Gentoo Linux for a minimalist web server’