Tag Archive for 'nginx'

Site is now running Nginx, Gentoo Linux in a Slicehost VPS

This site has been running the Nginx web server and Gentoo Linux in a Slicehost VPS (256MB) since last weekend. The migration process was surprisingly painless. I’m very happy with the performance so far. This is my first “production” web server, and I must say Gentoo makes it a breeze.

P.S. I’ve been meaning to document the migration process but haven’t found the time yet.

If you liked this post, please subscribe to my feed. Thanks for visiting!

Nginx: change the upload size limit

I learned today that the client_max_body_size directive in nginx.conf controls Nginx’s upload size limit. The default value appears to be 1MB. To allow uploads of up to 10MB, insert this line in nginx.conf:

client_max_body_size 10M

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.

Nginx with PHP as FastCGI on Gentoo Linux

Nginx (pronounced “Engine X”) is a high performance web server (and proxy server, but we will be using it as a web server here). In small VPS environments where memory is precious, Apache is at best overkill and uses memory that could be spent elsewhere (like MySQL query caching), at worst a terrible bottleneck that will consistently bring down your site under very moderate loads. If you are willing to live without .htaccess files and Apache-style mod_rewrite rules, Nginx is a great replacement that will lower memory usage and increase performance.

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

Continue reading ‘Nginx with PHP as FastCGI on Gentoo Linux’