S
S
shur1k2014-02-11 22:28:45
PHP
shur1k, 2014-02-11 22:28:45

Why is captcha not working in nginx?

Good afternoon!
Faced such a problem, dynamic capthca does not work in nginx. Previously, the site worked on apache + php was transferred to nginx + php-fpm.
The problem is that there is a captcha that is dynamically generated using the php controller is not displayed on the site, the following is in the logs:

2014/02/11 14:12:37 [error] 3029#0: *1 open() "/var/www/site.ru/captcha.jpg" failed (2: No such file or directory), client: 37.110.25.111, server: site.ru, request: "GET /captcha.jpg?1392145982456 HTTP/1.1", host: "www.site.ru", referrer: "http://www.site.ru/qna/"

Virtual host config:
location / {
            index  index.php;
            #auth_basic "Members Only";
            #auth_basic_user_file /etc/nginx/htpasswd;
            rewrite ^/image /image.php last;
            rewrite ^/web/(.*) /web/$1 last;
            rewrite ^/receiver.html /receiver.html last;
            rewrite ^/ /index.php last;
            #rewrite ^/captcha.jpg /controller/common.php last;
            #try_files $uri $uri/ /index.php;
        }

        #location /captcha.jpg {
        #}

        # Images and static content is treated different
        location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico|xml|ttf|woff|eof|swf)$ {
             access_log        off;
             expires           100d;
        }

If you remove .jpg from the static, then everything works, but half of the pictures are not displayed. I tried, as indicated in the comments, to give the kofiga directly, it also does not work. Who faced similar on nginx+php-fpm tell me how you decided.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2014-02-11
@Nc_Soft

Something like this (not tested)

location = /captcha.jpg {
//тут либо пхп обработчик либо реврайт
rewrite ^/captcha.jpg /controller/common.php last;
}

V
Valery Dmitriev, 2014-02-11
@rotor

What a nightmare you have in the config. You read to doc Sysoev. It is in Russian and very clearly written
. I have done something like this:

...
  location = /path/to/capcha.php {
    include  php5_provider;
  }
  location = /capcha {
    rewrite ^  /path/to/capcha.php?$uri last;
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question