nginx缓存cache的几种方式

官方详细参数:http://wiki.nginx.org/NginxHttpProxyModule
1、传统缓存之一(404)
这个办法是把nginx的404错误定向到后端,然后用proxy_store把后端返回的页面保存。

配置:
location / {root /home/html/;#主目录expires 1d;#网页的过期时间error_page 404 =200 /fetch$request_uri;#404定向到/fetch目录下}location /fetch/ {#404定向到这里internal;#指明这个目录不能在外部直接访问到expires 1d;#网页的过期时间alias /home/html/;#虚拟目录文件系统地址要和locaion /一致,proxy_store会将文件保存到这目录下proxy_pass http://xok.la/;#...

nginx 502错误分析解决

NGINX 502 Bad Gateway错误是FastCGI有问题,造成NGINX 502错误的可能性比较多。将网上找到的一些和502 Bad Gateway错误有关的问题和排查方法列一下,先从FastCGI配置入手:
1.查看FastCGI进程是否已经启动
NGINX 502错误的含义是sock、端口没被监听造成的。我们先检查fastcgi是否在运行
2.检查系统Fastcgi进程运行情况
除了第一种情况,fastcgi进程数不够用、php执行时间长、或者是php-cgi进程死掉也可能造成nginx的502错误
运行以下命令判断是否接近FastCGI进程,如果fastcgi进程数接近配置...

config –prefix=/server/openssl/openssl no-shared no-threads

环境:centos 5 nginx-0.7.61
在新增with-http_ssl_module编译选项后,编译报错:
make[1]: Entering directory `/xok.la/nginx-0.7.61′cd /server/openssl \        && make clean \        && ./config –prefix=/server/openssl/openssl no-shared  no-threads \        && make \        && make installmake[2]: Entering directory `/server/openssl’make[2]: *** No rule to make target `clean’.  Stop.make[2]: Leaving directory `/server/openssl’make[1]: *** [/serve...

nginx 漏洞(适用于0.1.0-0.8.14)补丁

漏洞介绍:
http://www.kb.cert.org/vuls/id/180065
As with a number of other web servers, nginx is designed to operate with a single privileged master process and multiple unprivileged worker processes handling specific requests. A remote, unauthenticated attacker may be able to execute arbitrary code in the context of the worker process or cause the worker process to crash, resulting in a […]

...

server_names_hash, you should increase server_names_hash_bucket_size: 32

版本:nginx/0.6.35
在增加了一个虚拟主机后,执行nginx -t测试报错:
could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32
于是我就在http区加上了
server_names_hash_bucket_size 32;
可是还是报错
[emerg] 11384#0: "server_names_hash_bucket_size" directive is duplicate in /usr/local/nginx/conf/nginx.conf:50
查了资料:
保存服务器名字的hash表是由指令 server_names_hash_max_size 和 server_names_hash_bucket_size所控制的。参数hash bucket size总是等于hash表的大小,并且是一路处理...

nginx的proxy_pass到$host的问题

在配置一个location的时候,希望使用一个变量如$host来指示nginx代理:
location /test/ {proxy_pass http://$host;}
如你想不到,这个配置是不能使用的,查看error.log,打出来的信息也无法帮助解决问题。
但相同情况下,root标签就工作得很好:
locatin /test/ {root /dev/shm/$host;}
令人匪夷所思,估计这是nginx的一个bug,或者是一个搅不清的逻辑?
把上面的错误配置改成
location /test/ {proxy_pass http://$host/;}
或者
set $vhost "test.sudone.com";location /test/ {proxy_pass http://$vh...

nginx rewrite中last和break的区别

在实际配置中,有的地方用last并不能工作,换成break就可以,其中的原理是对于根目录的理解有所区别,按我的测试结果大致是这样的。
#location / {#proxy_pass http://test;#alias /data/web/;#root /data/web;#rewrite "^/a/(.*)\.html$" /1.html last;#}
在#location / { 配置里:
1、使用root指定源:使用last和break都可以
2、使用proxy_pass指定源:使用last和break都可以
3、使用alias指定源:必须使用last
在location /a/或使用正则的location ~ ^/a/里:
1、使用root指定源:使用last和break都可以

nginx防盗链配置,设置

以下配置一般可称为图片防盗链配置.
例一:
location /images/ {
alias /data/images/;
valid_referers none blocked server_names *.xok.la xok.la ;
if ($invalid_referer) {return 403;}
}
例二:
location ~* \.(gif|jpg|png|swf|flv)$ {valid_referers none blocked xok.la www.xok.la;if ($invalid_referer) {rewrite ^/ http://www.xok.la/403.html;#return 404;}}
第一行:gif|jpg|png|swf|flv
表示对gif、jpg、png、swf、flv后缀的文件实行防盗链
第二行: xok.la www.xok.la
表示对 xok.la www.xok.la这2个来路进行判断
if{}里面内容...

有关nginx的worker_processes参数

worker_processes指明了nginx要开启的进程数,据官方说法,一般开一个就够了,多开几个,可以减少机器io带来的影响。
据实践表明,nginx的这个参数在一般情况下开4个或8个就可以了,再往上开的话优化不太大。据另一种说法是,nginx开启太多的进程,会影响主进程调度,所以占用的cpu会增高,这个说法我个人没有证实,估计他们是开了一两百个进程来对比的吧。
worker_processes配置的一些注意事项:
1、worker_cpu_affinity配置最好是能写上
我这里服务器多数是双核超线程,相...