Rewrite server responses

Hello list,

I have a nginx server that runs on 127.0.0.1:5004 (behind a load
balancer) and I’m having difficulties with HTTP responses.
It seems that the application (in PHP5, Dotclear) sends a 302 when I try
to connect to the admin panel, and this 302 redirects to :5004.

I there any way to rewrite that response in nginx ?

Thanks,
Julien

On Sat, Oct 02, 2010 at 11:49:50AM +0200, Julien Vehent wrote:

Hello list,

I have a nginx server that runs on 127.0.0.1:5004 (behind a load balancer) and I’m having difficulties with HTTP responses.
It seems that the application (in PHP5, Dotclear) sends a 302 when I try to connect to the admin panel, and this 302 redirects to :5004.

I there any way to rewrite that response in nginx ?

port_in_redirect off;


Igor S.
http://sysoev.ru/en/

On Sat, 2 Oct 2010 13:55:34 +0400, Igor S. [email protected] wrote:

On Sat, Oct 02, 2010 at 11:49:50AM +0200, Julien Vehent wrote:

Hello list,

I have a nginx server that runs on 127.0.0.1:5004 (behind a load balancer) and I’m having difficulties with HTTP responses.
It seems that the application (in PHP5, Dotclear) sends a 302 when I try to connect to the admin panel, and this 302 redirects to :5004.

I there any way to rewrite that response in nginx ?

port_in_redirect off;

I just put that in the location section, put it doesn’t seem to take
effect.


GET /blog/admin/ HTTP/1.1
Host: example.net
[snip]

HTTP/1.1 302 Moved Temporarily
Server: nginx/0.7.67
Date: Sat, 02 Oct 2010 10:14:30 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0,
pre-check=0
Pragma: no-cache
Location: http://example.net:5004/blog/admin/auth.php

The conf:


server {
listen 127.0.0.1:5004;
server_name example.net;

    access_log  /var/log/nginx/example.net.access.log;
    root   /var/www;
    index  index.php index.html index.htm;
    location /ressources {
            autoindex on;
    }
    location /blog/admin {
            port_in_redirect off;
    }
    location ~ \.php$ {
            include fastcgi_params;
            fastcgi_pass    unix:/var/run/spawn-fcgi-php5.socket;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME 

$document_root$fastcgi_script_name;
}
}

Julien

Try putting it into the php location instead.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,136235,136986#msg-136986

Hello!

On Mon, Oct 04, 2010 at 09:36:24PM +0200, Julien Vehent wrote:

            fastcgi_pass    unix:/var/run/spawn-fcgi-php5.socket;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    }

Could it be cached somewhere ?
I have haproxy as a frontend, but it really only does HTTP requests/responses balancing.

As long as you use fastcgi and your fastcgi application
returns wrong redirect - you should convince it to return correct
one by providing appropriate fastcgi_param’s.

Changing fastcgi_param SERVER_PORT to 80 should be enough as far
as I understand your case.

Rewriting of ‘Location’ header returned by backend only available
for proxy (see proxy_redirect directive), where it’s not possible
to control backend’s idea about correct server address.

Maxim D.

On Mon, 04 Oct 2010 12:20:54 -0400, “Dayo” [email protected] wrote:

Try putting it into the php location instead.

Still the same…


    location ~ \.php$ {
            port_in_redirect off;
            include fastcgi_params;
            fastcgi_pass    unix:/var/run/spawn-fcgi-php5.socket;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME 

$document_root$fastcgi_script_name;
}

Could it be cached somewhere ?
I have haproxy as a frontend, but it really only does HTTP
requests/responses balancing.

Julien

On Tue, 5 Oct 2010 14:55:22 +0400, Maxim D. [email protected]
wrote:

for proxy (see proxy_redirect directive), where it’s not possible
to control backend’s idea about correct server address.

Maxim D.

Got it ! Indeed, it was a FASTCGI environment variable. but not that
one.

I had

PHP only, required if PHP was built with --enable-force-cgi-redirect

fastcgi_param REDIRECT_STATUS 200;

And by commenting it out, I don’t have this redirect problem anymore.

That makes me think: where can I find detailled information about
FASTCGI environment variables and their meanings ? Some, like
SERVER_PORT are easy, but what about REMOTE_PORT for example ?

Thanks,
Julien

On Tue, 05 Oct 2010 13:37:52 +0200, Julien Vehent
[email protected] wrote:

Rewriting of ‘Location’ header returned by backend only available

And by commenting it out, I don’t have this redirect problem anymore.

Correction, setting SERVER_PORT to 80 was necessary as well.

Julien

On Tue, Oct 05, 2010 at 01:37:52PM +0200, Julien Vehent wrote:

That makes me think: where can I find detailled information about FASTCGI environment variables and their meanings ? Some, like SERVER_PORT are easy, but what about REMOTE_PORT for example ?

http://www.rfc-editor.org/rfc/rfc3875.txt may be a good start. It’s
about CGI but quite a lot of it applies to FastCGI as well.

REMOTE_PORT is the client’s TCP port. The connection between the client
and the web server is $REMOTE_ADDR:$REMOTE_PORT ->
$SERVER_ADDR:$SERVER_PORT

Best regards,
Grzegorz N.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs