现在nginx越来越火了,我的博客是CentOS+nginx+php+mysql+eaccelerator这种架构。只有一台服务器,所以想到用在让两个nginx分别监听IP:80和127.0.0.1:80.这样外面人看不出来的!哈哈!

1、安装nginx和nginx_cache_Purge.
wget http://labs.frickle.com/files/ngx_cache_purge-1.1.tar.gz
tar zxvf ngx_cache_purge-1.1.tar.gz

wget http://nginx.org/download/nginx-0.8.47.tar.gz
tar zxvf nginx-0.8.47.tar.gz
cd nginx-0.8.47/
./configure --prefix=/usr/local/nginx --user=www --group=www --add-module=ngx_cache_purge-1.1 --with-http_stub_status_module --with-http_ssl_module
make -j2 && make install
cd ../
2、nginx配置

cat /usr/local/nginx/conf/nginx.conf

user www www;

worker_processes 8;

error_log /usr/local/nginx/logs/nginx_error.log crit;

pid /usr/local/nginx/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;

events
{
use epoll;
worker_connections 65535;
}

http
{
include mime.types;
default_type application/octet-stream;

charset gbk;
#source_charset gbk;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 300m;

sendfile on;
tcp_nopush on;

keepalive_timeout 60;

tcp_nodelay on;

client_body_buffer_size 512k;
proxy_connect_timeout 5;
proxy_read_timeout 60;
proxy_send_timeout 5;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;

gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;


proxy_temp_path /home/proxy_temp_dir;

proxy_cache_path /home/proxy_cache_dir levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=30g;

upstream backend_server {
server 127.0.0.1:80 weight=1 max_fails=2 fail_timeout=30s;
# server 192.168.8.44:80 weight=1 max_fails=2 fail_timeout=30s;
# server 192.168.8.45:80 weight=1 max_fails=2 fail_timeout=30s;
}

server
{
listen 222.134.x.x:80;
server_name www.freebsdsystem.org blog.freebsdsystem.org freebsdsystem.org;
index index.html index.htm index.php;
root /usr/local/AUTOLEMP/www/www.freebsdsystem.org;

location /
{

proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_cache cache_one;

proxy_cache_valid 200 304 12h;

proxy_cache_key $host$uri$is_args$args;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://backend_server;

add_header X-Cache HIT-FreeBSDSYSTEM.org;
expires 1d;
}


location ~ /purge(/.*)
{

allow 127.0.0.1;
allow 219.146.0.0/16;
deny all;
proxy_cache_purge cache_one $host$1$is_args$args;
}


location ~ .*\.(php|jsp|cgi)?$
{
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://backend_server;
}

access_log off;
}
server
{
listen 222.134.66.153:80;
server_name www.huaanjiuyuan.com;
index index.html index.htm index.php;
root /usr/local/AUTOLEMP/www/wwwroot;

location /
{

proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_cache cache_one;

proxy_cache_valid 200 304 12h;

proxy_cache_key $host$uri$is_args$args;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://backend_server;

add_header X-Cache HIT-FreeBSDSYSTEM.org;
expires 1d;
}


location ~ /purge(/.*)
{

allow 127.0.0.1;
allow 219.146.0.0/16;
deny all;
proxy_cache_purge cache_one $host$1$is_args$args;
}


location ~ .*\.(php|jsp|cgi)?$
{
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://backend_server;
}

access_log off;
}
}

[/quote]

3.修改www.freebsdsystem.org的nginx.conf 将server中的listen 80; 为listen 127.0.0.1:80

4、重启两个nginx。即可在/home/proxy_cache_temp看到缓存的目录!

5、不要在代理缓存服务器中加入nginx_static_etags,不然你会哭的!

现在本博客架构变为nginx +nginx