Apache/Nginx Cache Last-Modified、Expires和Etag相关工作原理

使用ETag和Expires调优web 服务器性能
正确使用Etag和Expires标识处理,可以使得页面更加有效被Cache。
在客户端通过浏览器发出第一次请求某一个URL时,根据 HTTP 协议的规定,浏览器会向服务器传送报头(Http Request Header),服务器端响应同时记录相关属性标记(Http Reponse Header),服务器端的返回状态会是200,格式类似如下:
HTTP/1.1 200 OKDate: Tue, 03 Mar 2009 04:58:40 GMTContent-Type: image/jpegContent-Length: 83185Last-Modified: Mon, 22 Nov 2010 16:29:24 GMTCache-Control: max-age=2592000Expires: Thu, 02 Apr 2009 05:14:08 GMTEta...

nginx 405状态码解决

有项目需要提交POST到静态文件,但是nginx报405错误,对于这种情况的解释是,由于访问静态文件的时候只能使用GET方式,不能使用POST,因此呢,在nginx的返回信息中,在0.6.33版以后就增加了这么一个405错误状态码,意思就是,你不能用POST方式来请求静态文件,错了,要换个别的方法
尝试方法一
error_page 405 =200 @405;location @405{root /data/www/xok.la/;}
无法解决。
尝试方法二
location /welcome/{root /data/www/xok.la/;error_page 405 =200 /welcome/;}
解决。

...

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都可以