What is causing this 301 redirect?
Solution 1
The presence of an X-Powered-By: PHP header means that wordpress is issuing the 301. It's due to wordpress forcing www.mylesgray.com. When you use a nonstandard port, user agents will generally include the port in the Host: header. Try adding
fastcgi_param HTTP_HOST $host;
with the rest of your fastcgi_param directives (or alog with your "include fastcgi_params;") and it should fix this.
Solution 2
You should add a '/' at then end of your URLs. Furthermore if you run ab http://foo.com it will return you a "ab: invalid URL" error. If you do "ab -t 10 http://example.com/" everything will work fine. You should always use '/' in your URLs otherwize your webserver will try to redirect the page to the home page automatically for you which generates an undesirable extra load on the server and some extra bytes on the wire.
You web server told you what it did:
'/' is missing and something is incorrect with the port numer:
# curl -I http://www.mylesgray.com:8080
HTTP/1.1 301 Moved Permanently
[...]
======> Location: http://www.mylesgray.com/
'www' and '/' are missing:
# curl -I http://mylesgray.com
HTTP/1.1 301 Moved Permanently
[...]
=======> Location: http://www.mylesgray.com/
[...]
'/' and 'www' are missing:
# curl -I http://mylesgray.com:8080
HTTP/1.1 301 Moved Permanently
[...]
========> Location: http://www.mylesgray.com/
'hope that helps :)
Comments
-
Myles Gray about 4 years
I have a problem with my server redirecting
http://www.mylesgray.com:8080/
->http://www.mylesgray.com/
.Here are my Nginx
default
andfastcgi_params
config files:https://gist.github.com/1745271
https://gist.github.com/1745313
This is rather a nusance as I am trying to run a benchmark of Nginx w/ caching vs Varnish w/ caching on top of Nginx to see if there is any performance benefit of one over the other.
As such I have straight Nginx w/ caching listening on port
8080
and varnish on port80
which forwards any non-cached requests to Nginx onlocalhost:8080
, so obviously what I want to do is run anab
benchmark onhttp://www.mylesgray.com:8080/
and onhttp://www.mylesgray.com/
to see the difference.Here are the results of
curl -I
on various addresses.# 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/
Then running
curl -I http://www.mylesgray.com
gives:# 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
So as you can see
80
is served by Varnish and8080
by Nginx but I cannot find anywhere anything that does a 301 redirect, not innginx.conf
or in thesites-enabled/default
file and I don't believe it is caused by Wordpress itself but an very much open to correction.Please help, this is driving me nuts!
Myles
-
Myles Gray about 12 yearsI have added this to my
/etc/nginx/fastcgi_params
and restarted all services but curl is still showing 301's for all excepthttp://www.mylesgray.com
. -
Myles Gray about 12 yearsHere is my
default
site conf and myfastcgi_params
file respectively: gist.github.com/1745271 and gist.github.com/1745313 -
kolbyjack about 12 yearsWhich version of nginx are you running? Overriding request headers with fastcgi_param wasn't added until 0.8.40, it seems.
-
Myles Gray about 12 yearsAh... that may be it - I am running whatever comes with 10.04, I will reinstall with 1.0.11 and see how that goes...
-
Myles Gray about 12 yearsYou are the man! Excellent - works perfectly now!