External Redirect when expecting internal redirect

Thomas Glanzmann thomas at glanzmann.de
Sun Mar 10 12:30:22 UTC 2013


Hello,
I'm running nginx 1.2.1-2.2 on Debian Wheezy (testing). I try to obtain
the following:

Depending on the subnet accessing either rewrite internally to a cgi
script or to a static Website. For the cgi script that works perfectly
fine, for the static web site nginx always does a HTTP 301 instead of an
internal rewrite. Here is a stripped down configuration demonstrating the
issue:

(mini) [/etc/nginx] cat nginx.conf
user www-data;
pid /var/run/nginx.pid;

events {
        worker_connections 1024;
}

http {
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        geo $site {
                127.0.0.0/8 eva;
                default blank;
        }

        server {
                listen 80;
                server_name localhost;

                root /var/www;

                location /eva {
                        internal;
                        gzip off;

                        fastcgi_param   QUERY_STRING            $query_string;
                        fastcgi_param   REQUEST_METHOD          $request_method;
                        fastcgi_param   CONTENT_TYPE            $content_type;
                        fastcgi_param   CONTENT_LENGTH          $content_length;

                        fastcgi_param   REQUEST_URI             $request_uri;
                        fastcgi_param   DOCUMENT_URI            $document_uri;
                        fastcgi_param   DOCUMENT_ROOT           $document_root;
                        fastcgi_param   SERVER_PROTOCOL         $server_protocol;

                        fastcgi_param   GATEWAY_INTERFACE       CGI/1.1;
                        fastcgi_param   SERVER_SOFTWARE         nginx/$nginx_version;

                        fastcgi_param   REMOTE_ADDR             $remote_addr;
                        fastcgi_param   REMOTE_PORT             $remote_port;
                        fastcgi_param   SERVER_ADDR             $server_addr;
                        fastcgi_param   SERVER_PORT             $server_port;
                        fastcgi_param   SERVER_NAME             $server_name;

                        fastcgi_param   HTTPS                   $https;

                        fastcgi_pass unix:/var/run/fcgiwrap.socket;
                        fastcgi_param SCRIPT_FILENAME /home/sithglan/work/scripts/web/eva.pl;
                }

                location /blank {
                        internal;
                        autoindex on;
                        autoindex_exact_size off;
                }

                location = / {
                        rewrite ^ /$site last;
                }
        }
}
(mini) [/etc/nginx] /etc/init.d/nginx restart
Restarting nginx: nginx.
(mini) [/etc/nginx] curl -I http://192.168.0.7/
HTTP/1.1 301 Moved Permanently
Server: nginx/1.2.1
Date: Sun, 10 Mar 2013 12:28:44 GMT
Content-Type: text/html
Content-Length: 184
Location: http://192.168.0.7/blank/
Connection: keep-alive

(mini) [/etc/nginx] curl -I http://192.168.0.7/
HTTP/1.1 301 Moved Permanently
Server: nginx/1.2.1
Date: Sun, 10 Mar 2013 12:28:47 GMT
Content-Type: text/html
Content-Length: 184
Location: http://192.168.0.7/blank/
Connection: keep-alive

I would like to acomplish that when 127.0.0.0/8 access the webserver the client
is internally redirected to eva.pl, which works, but if another ip address
access a website from static files is displayed, which works was well if I drop
the 'internal' keyword from location /blank but not using an internal redirect.

What do I have to change in order to make the internal rewrite for the files
work?

Cheers,
        Thomas



More information about the nginx mailing list