Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 是什么导致了301重定向?_Linux_Redirect_Nginx_Http Status Code 301_Varnish - Fatal编程技术网

Linux 是什么导致了301重定向?

Linux 是什么导致了301重定向?,linux,redirect,nginx,http-status-code-301,varnish,Linux,Redirect,Nginx,Http Status Code 301,Varnish,我的服务器重定向有问题http://www.mylesgray.com:8080/->http://www.mylesgray.com/ 以下是我的Nginxdefault和fastcgi\u参数config文件: 这相当重要,因为我正在尝试在Nginx的基础上运行Nginx w/caching与Varnish w/caching的基准测试,以查看两者之间是否存在性能优势 因此,我在端口8080上有直接的Nginx带缓存侦听,在端口80上有varnish,它将所有未缓存的请求转发到local

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

以下是我的Nginx
default
fastcgi\u参数
config文件:

这相当重要,因为我正在尝试在Nginx的基础上运行Nginx w/cachingVarnish w/caching的基准测试,以查看两者之间是否存在性能优势

因此,我在端口
8080
上有直接的Nginx带缓存侦听,在端口
80
上有varnish,它将所有未缓存的请求转发到
localhost:8080
上的Nginx,显然,我想做的是在
http://www.mylesgray.com:8080/
和on
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-Ihttp://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提供服务,但是我在任何地方都找不到任何可以进行301重定向的东西,而不是在
Nginx.conf
站点启用/默认
文件中,我相信这不是由Wordpress本身引起的,而是一个非常值得纠正的问题

请帮帮我,这快把我逼疯了


迈尔斯

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

fastcgi_param HTTP_HOST $host;

使用其余的fastcgi_参数指令(或使用“include fastcgi_参数;”的alog),它应该可以解决这个问题。

您应该在URL的末尾添加一个“/”。此外,如果您运行ab,它将返回“ab:无效URL”错误。如果你做“ab-T10”,一切都会很好。您应该始终在URL中使用“/”,否则您的Web服务器将尝试为您自动将页面重定向到主页,这会在服务器上产生不需要的额外负载和一些额外的字节

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

缺少“/”且端口号不正确

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

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

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

'希望有帮助:)

我已将此添加到我的
/etc/nginx/fastcgi_参数中,并重新启动了所有服务,但curl仍显示除
http://www.mylesgray.com
。这是我的
默认
站点配置文件和我的
fastcgi_参数
文件:您正在运行哪个版本的nginx?用fastcgi_参数覆盖请求头似乎直到0.8.40才被添加。啊。。。这可能是它-我正在运行10.04附带的任何东西,我将用1.0.11重新安装,看看如何进行…你就是那个人!非常好-现在可以完美工作了!