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
on 2013-03-10 13:31
on 2013-03-10 13:57
On Sun, Mar 10, 2013 at 01:30:22PM +0100, Thomas Glanzmann wrote: Hi there, > 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. What do you expect the user to see with the static web site? As in, what content do you wish nginx to return? > location /blank { > internal; > autoindex on; > autoindex_exact_size off; > } > > location = / { > rewrite ^ /$site last; > } So, the request is for "/", nginx does a rewrite (internal) to "/blank", and that is a directory, so nginx does a redirect (external) to "/blank/". That's pretty much what I expect to happen. (Then the browser requests /blank/ and gets rejected because the location{} is marked "internal".) > 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? You can use an internal rewrite to a file, provided that you actually rewrite to a file. Here, you rewrite to a directory without including the trailing /. I confess I'm not sure what it is that you want to do. Possibly setting the default in the map to "blank/" will help? But you will have to decide what the next step for the user is. f -- Francis Daly francis@daoine.org
on 2013-03-10 14:28
Hello Francis, * Francis Daly <francis@daoine.org> [2013-03-10 13:57]: > You can use an internal rewrite to a file, provided that you actually > rewrite to a file. Here, you rewrite to a directory without including > the trailing /. I wanted to rewrite to a directory. I see my mistake now and it should have been obvious to me, but was not. > Possibly setting the default in the map to "blank/" will help? Yes, it resolved my issue. Now it works perfectly fine. Thank you for helping me out. I was searching for two hours now. Cheers, Thomas
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.