导致此301重定向的原因是什么?

时间:2012-02-05 12:11:14

标签: linux redirect nginx http-status-code-301 varnish

我的服务器重定向http://www.mylesgray.com:8080/ - > http://www.mylesgray.com/

以下是我的Nginx defaultfastcgi_params配置文件:

https://gist.github.com/1745271

https://gist.github.com/1745313

这是一个非常麻烦,因为我试图运行 Nginx w /缓存 vs Varnish w / on Nginx 之上的基准来查看是否有任何一个人的表现好处。

因此我直接在端口8080上监听Nginx w / caching,在端口80上清除端口localhost:8080上的varnish将任何非缓存请求转发到ab上的Nginx,这显然是我想要的要做的是在http://www.mylesgray.com:8080/http://www.mylesgray.com/上运行curl -I基准,以查看差异。

以下是各种地址# curl -I http://www.mylesgray.com:8080 HTTP/1.1 301 Moved Permanently Server: nginx/0.7.65 Date: Sun, 05 Feb 2012 12:07:34 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive X-Powered-By: PHP/5.3.2-1ubuntu4.7ppa5~lucid1 X-Pingback: http://www.mylesgray.com/xmlrpc.php Location: http://www.mylesgray.com/ # curl -I http://mylesgray.com HTTP/1.1 301 Moved Permanently Server: nginx/0.7.65 Content-Type: text/html; charset=UTF-8 X-Powered-By: PHP/5.3.2-1ubuntu4.7ppa5~lucid1 X-Pingback: http://www.mylesgray.com/xmlrpc.php Location: http://www.mylesgray.com/ Content-Length: 0 Date: Sun, 05 Feb 2012 12:15:51 GMT X-Varnish: 1419774165 1419774163 Age: 15 Via: 1.1 varnish Connection: keep-alive # curl -I http://mylesgray.com:8080 HTTP/1.1 301 Moved Permanently Server: nginx/0.7.65 Date: Sun, 05 Feb 2012 12:16:08 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive X-Powered-By: PHP/5.3.2-1ubuntu4.7ppa5~lucid1 X-Pingback: http://www.mylesgray.com/xmlrpc.php Location: http://www.mylesgray.com/ 的结果。

curl -I http://www.mylesgray.com

然后运行# curl -I http://www.mylesgray.com HTTP/1.1 200 OK Server: nginx/0.7.65 Content-Type: text/html; charset=UTF-8 X-Powered-By: PHP/5.3.2-1ubuntu4.7ppa5~lucid1 X-Pingback: http://www.mylesgray.com/xmlrpc.php Content-Length: 5132 Date: Sun, 05 Feb 2012 12:07:29 GMT X-Varnish: 1419774133 1419774124 Age: 30 Via: 1.1 varnish Connection: keep-alive 给出:

80

因为你可以看到8080由Varnish提供,nginx.conf由Nginx提供,但我找不到任何地方任何执行301重定向的内容,而不是{{1} }或在sites-enabled/default文件中,我不相信它是由Wordpress本身引起的,但是非常容易纠正。

请帮助,这让我疯了!

迈尔斯

2 个答案:

答案 0 :(得分:10)

您应该在网址的末尾添加“/”。此外,如果您运行ab http://foo.com,它将返回“ab:invalid URL”错误。如果你做“ab -t 10 http://example.com/”一切都会正常。你应该总是在你的URL中使用'/',你的网络服务器将尝试自动将页面重定向到主页,这会在服务器上产生不必要的额外负载,并在网络上产生一些额外的字节。

您的网络服务器告诉您它做了什么:

缺少

'/',端口数字

的内容不正确
# curl -I http://www.mylesgray.com:8080
HTTP/1.1 301 Moved Permanently
[...]
======> Location: http://www.mylesgray.com/

'www'和'/'缺少

# curl -I http://mylesgray.com
HTTP/1.1 301 Moved Permanently
[...]
=======> Location: http://www.mylesgray.com/
[...]

'/'和'www'缺失

# curl -I http://mylesgray.com:8080
HTTP/1.1 301 Moved Permanently
[...]
========> Location: http://www.mylesgray.com/

'希望有所帮助:)

答案 1 :(得分:2)

X-Powered-By:PHP标头的存在意味着wordpress正在发布301.这是由于wordpress强制www.mylesgray.com。使用非标准端口时,用户代理通常会在Host:标头中包含该端口。尝试添加

fastcgi_param HTTP_HOST $host;

使用其余的fastcgi_param指令(或者使用“include fastcgi_params;”),它应该解决这个问题。