Myl*_*ray 9 linux redirect nginx varnish http-status-code-301
我的服务器重定向问题http://www.mylesgray.com:8080/- > http://www.mylesgray.com/.
这是我的Nginx default和fastcgi_params配置文件:
https://gist.github.com/1745271
https://gist.github.com/1745313
这是一个非常麻烦的事情,因为我试图在Nginx之上运行Nginx w/caching vs Varnish w/caching的基准测试,看看是否有任何性能优势.
因此,我有直接Nginx w /缓存监听端口8080和端口清漆,80它将任何非缓存请求转发给Nginx localhost:8080,所以很明显我想要做的是运行ab基准测试,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/
Run Code Online (Sandbox Code Playgroud)
然后跑步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
Run Code Online (Sandbox Code Playgroud)
因此,你可以看到80由Varnish和8080Nginx服务,但我无法找到任何进行301重定向的任何地方,不在文件中nginx.conf或sites-enabled/default文件中,我不相信它是由Wordpress本身引起的,但是非常容易纠正.
请帮忙,这让我疯了!
迈尔斯
Jér*_*e R 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/
Run Code Online (Sandbox Code Playgroud)
'www'和'/'缺少:
# curl -I http://mylesgray.com
HTTP/1.1 301 Moved Permanently
[...]
=======> Location: http://www.mylesgray.com/
[...]
Run Code Online (Sandbox Code Playgroud)
缺少'/'和'www':
# curl -I http://mylesgray.com:8080
HTTP/1.1 301 Moved Permanently
[...]
========> Location: http://www.mylesgray.com/
Run Code Online (Sandbox Code Playgroud)
'希望有帮助:)
X-Powered-By: PHP 标头的存在意味着 WordPress 正在发出 301。这是由于 WordPress 强制使用 www.mylesgray.com。当您使用非标准端口时,用户代理通常会在 Host: 标头中包含该端口。尝试添加
fastcgi_param HTTP_HOST $host;
Run Code Online (Sandbox Code Playgroud)
与您的 fastcgi_param 指令的其余部分(或与您的“include fastcgi_params;”类似),它应该可以解决这个问题。