A
A
akashtrih2015-04-17 17:33:19
Nginx
akashtrih, 2015-04-17 17:33:19

"Rewrite or internal redirection cycle..." error. Why?

There is nginx, and under it is apache.
There are image files at `/uploads/images...`, requests to which are redirected to the script, and the latter decides whether to give the image or redirect the user to the login page.
.htaccess:

RewriteCond %{REQUEST_URI} ^/uploads.*
RewriteRule ^(.*)$ ./getpics.php [L]

Images are served by nginx by passing the `X-Accel-Redirect` header. nginx has the following settings:
location /uploads {
                internal;
                alias /files/uploads;
        }

However, instead of a picture, I get a 500 error from nginx:
rewrite or internal redirection cycle while internally redirecting to "/uploads/images/00/0…" while reading response header from upstream, client: 66.87……, server: server.org, request: "GET /uploads/images/0… HTTP/1.1", upstream: "http://127.0.0.1:80/uploads/images/00…", host: "server.org"

Full config /etc/nginx/sites-enabled/sitename:
server {
        listen   123.45.67.89:80; ## listen for ipv4; this line is default and implied

        root /var/www/sitename;
        index index.php index.html index.htm;

        # Make site accessible from http://localhost/
        server_name sitename.com;

        location /uploads/images/ {
                proxy_buffers 8 32k;
                proxy_buffer_size 64k;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $remote_addr;
                proxy_set_header RawURI $request_uri;
                if ($check) {
                        proxy_pass http://127.0.0.1:80;
                        break;
                }
                root /var/www/sitename;
        }

        location / {
                proxy_buffers 8 32k;
                proxy_buffer_size 64k;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $remote_addr;
                proxy_set_header RawURI $request_uri;
                proxy_pass http://127.0.0.1:80;
        }

        # http://stackoverflow.com/questions/16189758/serve-large-file-with-php-and-nginx-x-accel-redirect
        location /uploads {
                internal;
                alias /files/uploads;
        }

        location ~ (\.mp3|avatar_\d+x\d+\.(jpe?|pn)g)$ {
        }
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
akashtrih, 2015-04-21
@akashtrih

In general, the problem was in the rule location /uploads/images/ {that worked before location /uploads {, redirected the request to Apache, which ran the script, which again redirected to Enginx, then to Apache, etc.
I solved it in this way: in the root of the site I created a symlink to / files with the name dwnld, in the nginx config I wrote

location /dwnld/ {
    internal;
    root /var/www/sitename;
}

And in the script I pass the title of the view:
Accessing files from outside is the same:http://sitename.com/uploads/file.jpg

S
ShamblerR, 2015-04-17
@ShamblerR

as an option it could be something like this

uploads
/files/uploads
/files/uploads/files/uploads
/files/uploads/files/uploads/files/uploads
/files/uploads/files/uploads/files/uploads/files/uploads
/

In general, give the whole nginx config

V
Vlad Zhivotnev, 2015-04-17
@inkvizitor68sl

> alias /files/uploads;
Do you have such a directory on the file system?
And in general there is no point in using alias, write root /path/on/file/system/files;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question