# Can nginx hide port number and rewrites for virtualhost?

**URL:** <https://www.ruby-forum.com/t/can-nginx-hide-port-number-and-rewrites-for-virtualhost/165196>\
**Category:** NGINX\
**Created:** [April 10, 2009, 3:06am UTC](https://www.ruby-forum.com/t/can-nginx-hide-port-number-and-rewrites-for-virtualhost/165196 "2009-04-10T03:06:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sdotsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@sdotsen](https://www.ruby-forum.com/u/sdotsen)\
**Post date:** [April 10, 2009, 3:06am UTC](https://www.ruby-forum.com/t/can-nginx-hide-port-number-and-rewrites-for-virtualhost/165196/1 "2009-04-10T03:06:26Z")

</div>

I’m running Oracle Collab Suite on port 7777 and 7778. Oracle installed  
its own Apache and hacking it has proven to be difficult. For one thing,  
I can’t seem to get VirtualHost to work correctly. Since it doesnt use  
port 80 by default, I decided to put nginx in front of it. I managed to  
proxy pass port 80 to 7778. However, it doesnt stop there. Here’s how  
things are now.

My mail is pointed to the following URL:  
[http://mail.domain.com:7778/ocsclient/](http://mail.domain.com:7778/ocsclient/)  
My conferencing portal is pointed to:  
[http://mail.domain.com:7778/imtapp/app/prelogin.uix](http://mail.domain.com:7778/imtapp/app/prelogin.uix)

As you can see, the URLs are pointed to mail because that’s what the  
machine name is called. I managed to create a CNAME which works but once  
it redirects after you log in, it goes back to  
[http://mail.domain.com:7778/](http://mail.domain.com:7778/)…  
So, two things …

1 - How can I hide the port number, I think I got it to work using  
proxy\_pass but that only seems to work for one “server.”

server {  
listen 80;  
server\_name [mail.domain.com](http://mail.domain.com);

```
location / {
  index index.html;
  proxy_pass http://mail.domain.com:7778;
}

```

}

I added a second “server” directive for “[conference.domain.com](http://conference.domain.com)” but it  
sends me in a loop.

2 - How can I rewrite my URL so that if I go to “[conference.domain.com](http://conference.domain.com)”  
it doesn’t change to “[mail.domain.com](http://mail.domain.com).” Don’t forget the app was  
installed and takes the hostname of the server which is [mail.domain.com](http://mail.domain.com).

Posted at Nginx Forum: [Can nginx hide port number and rewrites for virtualhost?](http://forum.nginx.org/read.php?2,944,944#msg-944)

---

<div class="post-metadata">

**Author:** ![sdotsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@sdotsen](https://www.ruby-forum.com/u/sdotsen)\
**Post date:** [April 10, 2009, 8:19am UTC](https://www.ruby-forum.com/t/can-nginx-hide-port-number-and-rewrites-for-virtualhost/165196/2 "2009-04-10T08:19:22Z")

</div>

On Thu, Apr 09, 2009 at 08:56:59PM -0400, sdotsen wrote:

> server {
> 
> 2 - How can I rewrite my URL so that if I go to “[conference.domain.com](http://conference.domain.com)” it doesn’t change to “[mail.domain.com](http://mail.domain.com).” Don’t forget the app was installed and takes the hostname of the server which is [mail.domain.com](http://mail.domain.com).

[http://wiki.nginx.org/NginxHttpProxyModule#proxy\_redirect](http://wiki.nginx.org/NginxHttpProxyModule#proxy_redirect)

However, it rewrites "Location"s header only. It can not rewrite links  
inside HTML.
