linux - 是什么导致了这个 301 重定向?

标签 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在 Nginx 之上带缓存的 Varnish 的基准测试,看看是否有任何一个比另一个的性能优势。

因此,我有直接的 Nginx w/缓存监听端口 8080 和 varnish 在端口 80 上转发任何非缓存请求到 localhost 上的 Nginx: 8080,所以很明显我想做的是在 http://www.mylesgray.com:8080/ 上运行一个 ab 基准测试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 由 Varnish 提供,8080 由 Nginx 提供,但我找不到 anywhere 任何执行 301 重定向的东西,不在 nginx.confsites-enabled/default 文件中,我不认为这是由 Wordpress 本身引起的,但非常愿意更正。

请帮忙,这让我抓狂!

迈尔斯

最佳答案

您应该在 URL 的末尾添加一个“/”。此外,如果您运行 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/

'希望有帮助:)

关于linux - 是什么导致了这个 301 重定向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9149124/

相关文章:

node.js - 我应该同时使用 Nginx 和 HAProxy 作为生产 Node 应用程序吗?

c++ - 在 dlclose() 之后访问由共享库分配的内存

linux - 识别不包含具有特定字符串的文件的文件夹

linux - 如何使用命令检查 Linux 中进程的 I/O 利用率

linux - 如何使用 grep 对标题和模式进行 grep

javascript - 快速重定向并传递 JavaScript 变量

redirect - Nginx 反向代理。 1个外部IP,2个本地服务器

php - 我们可以使用 javascript 检索和设置 PHP cookie 吗

ruby-on-rails - Rails + (Phusion Passenger|Puma|Unicorn|Thin) + (Nginx|Apache) 如何协同工作?

linux - Sonarqube在Centos7上加载css和js相关内容失败