2

I set up nginx as a reverse proxy for Drupal. Static files are served from a different domain. It works well, imagecache files are generated well, too. But the problem is: when the derivated image does not exist, the request for this image returns a redirect with the content-type:text/html, and Facebook or jQueryMobile (only when running in an iPhone, not in desktop browser) does not like it.

The context: when a file is requested from mycdn.com, if it does not exist, it is redirect to mysite.com which is a site that does the reverse proxy. So, it can be seen that imagecache does nothing here, just a use case. The question here: why nginx adds a text/html when it does a redirect?

Here is the scenario:

GET http://mycdn.com/sites/default/files/imagecache/gallery/myfile.jpg

Server  nginx
Date    Tue, 26 Jul 2011 05:28:09 GMT
Content-Type    text/html
Content-Length  154
Connection  keep-alive
Location    http://mysite.com/sites/default/files/imagecache/gallery/myfile.jpg
Expires Thu, 25 Aug 2011 05:28:09 GMT
Cache-Control   max-age=2592000

then the result of the redirect

GET http://mysite.com/sites/default/files/imagecache/gallery/myfile.jpg
Server  nginx
Date    Tue, 26 Jul 2011 05:28:10 GMT
Content-Type    image/jpeg
Connection  keep-alive
X-Powered-By    PHP/5.2.17
Expires Tue, 09 Aug 2011 05:28:10 GMT
Cache-Control   max-age=1209600, private, must-revalidate
Etag    "58a657c2ee47424f202387000c191b7e"
Set-Cookie  DRUPAL_UID=64; expires=Thu, 18-Aug-2011 09:01:29 GMT; path=/; domain=.thongtincongnghe.com
Vary    Cookie,Accept-Encoding,User-Agent
Last-Modified   Tue, 26 Jul 2011 05:28:10 GMT
Content-Encoding    gzip
Content-Length  1400

nginx configuration on mycdn.com (I removed unrelated info):

server {
    listen       80;
    server_name mycdn.com;
    root   /home/ttcn/public_html;
    expires 30d;

    location / {
        try_files $uri @redirect;
    }

    location @redirect {
        rewrite ^(.*)$ http://mysite.com$1;
    }
}

Brief, with a desktop browser, there is no difference. Everything works flawlessly. But jQueryMobile on a mobile does not work (until the derivated image is generated, through a desktop browsing), Facebook OpenGraph does not work (I put the derivated image url in the og:image value) - it does not take that image until it exists on the server.

  • So the answer is there is nothing wrong with it. The problem comes elsewhere. – jcisio Aug 11 '11 at 11:21
2
+50

There is nothing wrong with the redirect having a content type of text/html. On the contrary, it is actually mandated by the HTTP/1.1 specification itself:

The temporary URI SHOULD be given by the Location field in the response. Unless the request method was HEAD, the entity of the response SHOULD contain a short hypertext note with a hyperlink to the new URI(s).

The cache control header might be confusing Webkit mobile. Have you tried add expires off; inside the location @redirect block?

  • I've just added "expires off;" in the @redirect block, but it does not help. I don't know if it is Webkit mobile mor jQuery Mobile problem, because it worked before in jQM alpha2 (not sure which version of webkit mobile). BTW I think you had a correct answer about content-type even the problem is not solved, I'll wait a day before giving out the bounty ;) – jcisio Aug 10 '11 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.