fak3r

dim high beams for oncoming traffic


HOWTO: Configure nginx for Debian / Ubuntu

nginx_small HOWTO: Configure nginx for Debian / UbuntuUPDATE: I’m reworking my config blending in the security ideas found on camomel.org they’re really thought things through on this, this should make for a very secure environment.

I’m always trying new software, and with the I’ve moved from 1.3 to 2.0 to 2.2, and then later I moved everything over to , which I’ve liked, save for some memory issues that popped up.  Now, enter a web server named nginx (engine x), written by a Russian hacker. It’s already proved it’s meddle by running some of the largest Russian sites for years now.  It has the speed of Lighttpd, but with none of that memory weirdness, plus it uses a fraction of the CPU, so scaling should be smooth for highly visited sites.  It also does cool things like load balancing, reverse proxy, IMAP and POP proxy, etc, so I can see it being used in a variety of ways on a network.  It took me some time to understand how to configure it, which was a case of me just making it harder than it really is, so I wanted to post it here.  Look for updates as we go along, but this is currently backing a Production site I manage.

user					www-data www-data;
worker_processes  			5;
pid 					/var/run/.pid;
events {
worker_connections 1024;
}
http {
include				/etc//mime.types;
default_type			application/octet-stream;
log_format main 		'$remote_addr $host $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” “$http_user_agent” ‘
‘”$request_time” “$gzip_ratio”‘;
access_log			/var/log//access.log  main;
error_log			/var/log//error.log;
sendfile 			on;
tcp_nopush        		on;
tcp_nodelay      		off;
keepalive_timeout		65;
gzip				on;
gzip_http_version		1.1;
gzip_vary			on;
gzip_comp_level 		6;
gzip_buffers			16 8k;
#gzip_proxied			expired no-cache no-store private auth;
gzip_proxied 			any;
gzip_min_length			1000;
gzip_types			text/plain text/html text/css application/json application/x-javascript
text/xml application/xml application/xml+rss text/javascript;
server {
listen			80;
client_max_body_size	50M;
server_name 		server.domain.com;
root 			/var/www;
index  			index.html index.;
access_log  		/var/log//access.log  main;
error_page   		500 502 503 504  /500.html;
location = /500.html {
root		/var/www;
}
location ~* ^.+.(jpg|jpeg|gif)$ {
root		/var/www;
expires         30d;
}
location ~ \.$ {
include /etc//fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.;
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
}
}
}

HOWTO: determine optimal fastcgi settings for Lighttpd

PHP Fast-cgiAnyone building a server with a LAMP stack today has tons of options, mine have evolved to using Varnish -> -> Xcache -> -> MySQL. Once I had Lighttpd (aka Lighty) installed and running pages I looked to optimize the configuration and push it as hard as possible for more speed. Of course lately I’ve been getting unexplained slowdowns, with many instances of -cgi appearing to be taking up almost all of my available CPU on `top`. Reading up on things it appears that I had , along with , set far too high for the load I’m getting. When you start it gives you the number of processes you’ve define, and then those in turn spawn the number of children you’ve specified. While my settings were too high, they were really overshooting things when you take into account that I’m using Xcache (which provides pre-caching) and Varnish (for HTTP acceleration). So even though one of my dynamic sites that I’m working on to ‘monetize’ things is getting 700-800 hits each day, my caching strategy is taking the load away from the ever available . Because of this, has much less to do, so giving it a ton of processes to just sit there and eat memory until they’re zombified is a waste. After reading the lighty FAQ and other posts specific to this, I’ve settled on the this for my fastcgi config block within my .conf file. (more…)


  • Recent Comment

    • Daniella Newmark: Greetings, I would like to help you solve your problem. We are a global content delivery network...
    • Jason Thurow: What type of files are you moving and to where? I work for a company that offers a software solution...
    • Justin Peron: Hey there. I can give you a run-down of what a CDN is and how they work. Also I can give you an idea of...
    • chris: great site tons of great articles very useful information <a href=”http://www.adve...
    • Baba: Bloxtr is nothing but eyeOS hosted on a website bloxtr.com – They have done a good deed, but should not...