URI rewrite with port number

Maxim Dounin mdounin at mdounin.ru
Mon Dec 20 00:18:50 MSK 2010


Hello!

On Sun, Dec 19, 2010 at 04:10:42PM -0500, microchip wrote:

> Hi,
> 
> I'm trying to rewrite 'www.somedomain.com:8080' to 'somedomain.com:8080'
> but when I use the below, it doesn't work. Any ideas? :)
> 
> if ($host != "somedomain.com:8080" ) {
>     rewrite  ^/(.*)$  "http://somedomain.com:8080/$1"  permanent;
> }

server {
    listen 8080 default;
    server_name _;
    rewrite ^ http://somedomain.com:8080$request_uri? permanent;
}

server {
    listen 8080;
    server_name somedomain.com;
    ...
}

See here for more details:

http://nginx.org/en/docs/http/request_processing.html

Maxim Dounin



More information about the nginx mailing list