Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In my config file I use

location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
        access_log        off;
        expires           30d;
        root /var/www;

However, I have a PHP script that generates a captcha image which does not have an ending. nginx does not display the image. What can I do to solve this?

share|improve this question
up vote 0 down vote accepted

Make it have an ending, or have it send image headers and catch those headers in Nginx.

share|improve this answer
Thanks Aleksey, how do you go about catching image headers? – Frank Vilea Jul 6 '11 at 16:35
Not sure about Nginx. You can also just put your Captcha image within /captcha/* and have location rule for that. – Aleksey Korzun Jul 6 '11 at 16:45
Hmm.. the captcha is actually dynamically generated in php and the link to it is ../captcha/?PHPSESSID=k3uml35066lcop6q4r9tf5ajk7 So there is never actually an image saved.. – Frank Vilea Jul 6 '11 at 16:51
So why can't you add location directive to catch /captcha/* and turn off access log/set expire. – Aleksey Korzun Jul 6 '11 at 16:53
@Frank Vilea If it's always dynamically generated you should just make sure PHP sets the correct content header. Nginx is just serving the PHP output and won't set any headers unless one is required per the RFC and not yet defined. – Martin Fjordvald Jul 7 '11 at 1:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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