nginx redirect problem

Igor Sysoev igor at sysoev.ru
Thu Mar 24 11:23:42 MSK 2011


On Thu, Mar 24, 2011 at 09:26:42AM +0800, lhmwzy wrote:
> here is the conf:
> 
>     server {
>         listen       10.68.150.4:82;
>         server_name  h.test.com;
>         root /usr/www;
> 
>         location / {
>             index  index.html index.htm index.php;
>         }
> 
>         error_page   500 502 503 504  /50x.html;
>         location = /50x.html {
>             root   /usr/local/www/nginx-dist;
>         }
> 
>         location ~ \.php$ {
>                 fastcgi_pass unix:/tmp/php-fastcgi.sock;
>                 include        fastcgi_params;
>                 fastcgi_index  index.php;
>         }
>     }
> 
> I have a router in the front,and have set a port map
> 
> 67.xx.xx.xx:8081-->10.68.150.4:82
> 
> But there is a problem
> When I visit http://h.test.com:8081/house,the  redirected to
> http://h.test.com/house/.
> How can make it redirct http://h.test.com:8081/house/ when visit
> http://h.test.com:8081/house?

You can try the following:

     server {
         listen       10.68.150.4:82;
         server_name  h.test.com:8081  h.test.com;

         location / {
              server_name_in_redirect on;
              port_in_redirect        off;
              ...

"server_name_in_redirect on" forces to use a fictitious first server_name
"h.test.com:8081" in a redirect. "port_in_redirect off" disables
a real 82 port in redirect. If you omit port_in_redirect you will get

http://h.test.com:8081:82/house/


-- 
Igor Sysoev
http://sysoev.ru/en/



More information about the nginx mailing list