#varnish server
upstream varnish_server{
server 127.0.0.1:6081;
}
upstream squid_server{
server 127.0.0.1:3128;
}
#load balance
upstream load_balance{
fair;
server 127.0.0.1:86 weight=1;
#server 127.0.0.1:3128 weight=1;
server 127.0.0.1:88 weight=1;
}
server {
listen 80;
# server_name _;
server_name www.phpjx.com;
# return 500;
server_tokens off;
autoindex on;
access_log /var/www/html/phpjx_ngx/access.log;
error_log /var/www/html/phpjx_ngx/error.log;
location / {
# auth_basic "phpjx";
# auth_basic_user_file /var/www/html/phpx_ngx/passwd1;
#deny 117.144.207.114;
allow all;
root /var/www/html/phpjx_ngx;
index index.html index.php index.htm;
}
error_page 404 /error.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
#用于清除缓存,假设一个URL为http://192.168.4.178/test.gif,通过访问
#http://192.168.4.178/purge/test.gif可以清除该url的缓存
location ~ /purge(/.*)
{
proxy_cache_purge cache_one $host$1$is_args$args;
allow all;
#error_page 405 =200 /purge$1;
}
#修改配置时,nginx与apache可能都需要重启的!!!
#nginx expire
#location ~ .*\.(flv|ico|swf|)(.*) {
location ~ .*(flv|ico|swf|list|index)(.*) {
proxy_cache cache_one;
proxy_cache_valid 200 302 1m;
proxy_cache_valid 301 2m;
proxy_cache_valid any 3m;
expires 10m;
proxy_pass http://127.0.0.1:88;
proxy_redirect off;
#比较重要,可以解决路径的问题,如果去掉,那么proxy_pass要指定详细的域名
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_cache_key $host$uri$is_args$args;
}
#location ~ \.(js|css)$ {
location ~ \.(css)$ {
proxy_pass http://squid_server;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_buffer_size 64k;
#proxy_buffers 4 64k;
}
# location ~ .*\.(txt)(.*) {
location ~ .*(txt|show)(.*) {
proxy_pass http://varnish_server;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_buffer_size 64k;
#proxy_buffers 4 64k;
}
#location ~ \.(txt|css)(.*) {
#tupian server
location ~ \.(jpg|gif|png)$ {
proxy_pass http://load_balance;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffer_size 64k;
proxy_buffers 4 64k;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/phpjx_ngx$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
location ~* \.(txt|sql)$ {
if (-f $request_filename) {
root /var/www/html/phpjx;
rewrite ^ /nofind.jpg break;
}
}
}