标签归档:nginx

nginx反向代理配置keepalive

有个项目上的Keep-Alive配置一直不起作用,检查了很久代码找不到问题,然后灵光一现想到应该是反向代理配置的问题

即:client—–nginx proxy—–real server

client配置了使用keepalive,real server也支持,问题就在于nginx代理没配置对

配置方式如下:

1、配置upstream,keepalive需要在upstream里配置


upstream http_backend {
server 127.0.0.1:8080;

keepalive 16;
}

2、修改proxy设置,proxy_http_version必须设置为“1.1”,且需要清空Connection头


server {

location /http/ {
proxy_pass http://http_backend;
proxy_http_version 1.1;
proxy_set_header Connection “”;

}
}

参考资料:http://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive

解决nginx的404页面使用SSI时循环嵌套的问题

问题场景:

1、nginx配置了404页面且指向一个使用了SSI include的页面(例如:404.shtml)
2、由于配置等原因,404.shtml中include的内容也不存在(也返回404)

造成结果:
request->404->redirect to 404.shtm->include a 404.shtml->include…
从而导致所有nginx的工作进程都被此请求的死循环block住

解决办法:

参考nginx SSI的文档,利用block语句和include语句中的stub属性:

stub — The name of the block to use as a default if the request is empty or returns an error.

首先在404.shtml中定义一个block:


SSI Not Found

然后在需要include的地方使用stub将include出错时的内容指向上面定义的block:


IE的“c00ce56e”bug

很简单的一个jQuery AJAX请求文件,IE8下报:

Could not complete the operation due to error c00ce56e.

检查网上都说是编码问题,不过写的不是太明确,因为我们服务器的文件编码都已经是UTF-8
最后找到说明

The problem occurs when setting the charset of a response to a XMLHttpRequest to utf8 instead of UTF-8 or ISO-8859-1 instead of ISO8859_1. IE7 is very strict on naming of the charsets.

“ISO8859_1” is the canonical representation of the Latin-1 character encoding string in the Java language and class libraries. The standard that is defined by the Internet Assigned Numbers Authority, however, is “ISO-8859-1”, which is not an accepted alias.

For more information refer: http://support.microsoft.com/default.aspx?scid=kb;en-us;304625

于是打开nginx的配置文件,把所有“utf8”替换成“UTF-8”,问题解决