URI rewrite with port number

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? :slight_smile:

if ($host != “somedomain.com:8080” ) {
rewrite ^/(.*)$ “http://somedomain.com:8080/$1” permanent;
}

Posted at Nginx Forum:

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? :slight_smile:

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 D.

Oh, I see :slight_smile: Thanks, will give it a try. Also bookmarked the site.

Posted at Nginx Forum:

hmm, it does not seem to work here. This is what I have so far, but when
I add www at the beginning of the hostname, it can’t find it. I should
note that I’m using a hostname from DynDNS but I doubt that’s an issue
since I have used lighttpd in the past and it successfully rewrites

server {
listen *:8080 default_server;
server_name _;
return 444;
}

server {
    server_name  xxx.xxx.xxx;
    listen       *:8080 rcvbuf=64k backlog=128;
    limit_conn   gulag 5;
    charset      utf-8;
    access_log   /var/log/nginx/xxx.access.log;
    root         /srv/www/htdocs/xxx.xxx.xxx;
    location / {
        index  index.php;
    }

Posted at Nginx Forum:

oops, forgot the add the rewrite ^
http://somedomain.com:8080$request_uri? permanent; in first server, but
it doesn’t work

Posted at Nginx Forum:

Maxim D. Wrote:

It won’t as long as you still have “return 444;”
before it.

Maxim D.


nginx mailing list
[email protected]
nginx Info Page

yes, yes, I did a wrong paste of an older config, but even with the
below one, it still doesn’t work for me, which has my head scratching

server {
listen *:8080 default_server;
server_name _;
rewrite ^ http://xxx.xxx.xxx:8080$request_uri? permanent;
}

server {
server_name xxx.xxx.xxx;
listen *:8080 rcvbuf=64k backlog=128;
limit_conn gulag 5;
charset utf-8;
access_log /var/log/nginx/xxx.access.log;
root /srv/www/htdocs/xxx.xxx.xxx;
location / {
index index.php;
}

Posted at Nginx Forum:

Hello!

On Wed, Dec 22, 2010 at 12:44:48PM -0500, microchip wrote:

oops, forgot the add the rewrite ^
http://somedomain.com:8080$request_uri? permanent; in first server, but
it doesn’t work

It won’t as long as you still have “return 444;” before it.

Maxim D.