Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

So I currently have a glassfish 3.1 server and an apache 2.2 server running on a single box. However I am trying to figure out to route some traffic through the apache server to the glassfish server in order to hide the non-standard ports 8080,8181. I also have static content being served up on the apache server. I have done some searching and have read several examples that talk about doing this, however I am really new to apache and I am not understanding the virtualhost and mod_proxy stuff. Any help understanding these, and how to accomplish what I am trying to do would be great.

EDIT

Per Shane example I tried the following.

<VirtualHost *:80>
    ServerName forum.mydomain.com
    # any logging config, etc, that you need
    ProxyPass / http://127.0.0.1:8080/forum/
    ProxyPassReverse / http://127.0.0.1:8080/forum/
</VirtualHost>

But now all my traffic is going to http://127.0.0.1:8080/forum/ and for some reason all the images are missing. So let me better explain my scenario. I have an apache server that serves up static pages, those pages are access from mydomain.com. Than I have a forum which runs as a web app on my glassfish server and they are served on mydomain.com:8080/forum/ what I would like to do is have forum.mydomain.com go to the mydomain.com:8080/forum/ but hide the port 8080 from the user. Let me know what you think.

EDIT PART 2

So since my last attempt did not work I decided to try another deviation of Shane's examples so I tried the following.

 <VirtualHost *:80>
    ServerName mydomain.com
    ServerAlias subdomain.mydomain.com
    DocumentRoot "/usr/local/apache/htdocs"

    <Location /forum>
       ProxyPass http://127.0.0.1:8080/forum/
       ProxyPassReverse http://127.0.0.1:8080/forum/
    </Location>
</VirtualHost>

But this did not work either, now if I hit mydomain.com it takes me to mydomain.com//forums/list.page but it is a 404 Error (I think this is strange because it obviously got to the glassfish server because it re-routed to the list.page). However if I go to subdomain.mydomain.com it takes me to my normal static web pages. I feel like I have to be close but I am just not sure what is wrong. In this example I was hoping that mydomain.com and subdomain.mydomain.com would take me to my static pages, and mydomain.com/forum/ would take me to my forum app on glassfish.

EDIT Part 3 Final?

So I finally got the routing how I wanted it BUT for some reason the forum is missing all of its images. I ended up doing it with the following.

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName www.mydomain.com
    ServerAlias subdomain.mydomain.com mydomain.com
    DocumentRoot "/usr/local/apache/htdocs"

</VirtualHost>


<VirtualHost *:80>
    ServerName forum.mydomain.com
    # any logging config, etc, that you need
    ProxyPass / http://127.0.0.1:8080/forum/
    ProxyPassReverse / http://127.0.0.1:8080/forum/
</VirtualHost>

Now I just need to figure out the image problem . . .

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Basically, the ProxyPass directives can serve requests to a location with content from a different HTTP (or AJP) server.

Here's an example config with comments that might help clarify:

# We'll call this your existing vhost:
<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /path/to/www/
    # other existing config
    # Let's say you want to serve http://example.com/glassfishapp from the 8080 listener:
    <Location /glassfishapp>
        ProxyPass http://127.0.0.1:8080
        ProxyPassReverse http://127.0.0.1:8080
    </Location>
</VirtualHost>

# Now, let's say there's a whole domain you want to serve from the 8181 listener:
<VirtualHost *:80>
    ServerName glass.example.com
    # any logging config, etc, that you need
    ProxyPass / http://127.0.0.1:8181/
    ProxyPassReverse / http://127.0.0.1:8181/
</VirtualHost>
share|improve this answer
    
Hello, so I tried this but it didn't work. <VirtualHost *:80> ServerName forum.mydomain.com # any logging config, etc, that you need ProxyPass / 127.0.0.1:8080/forum ProxyPassReverse / 127.0.0.1:8080/forum </VirtualHost> Where /forum/ is a webapp running on my glassfish instance on port 8080 –  EpicOfChaos Jan 15 '12 at 2:06
    
Please edit your question with this new info, since it can be formatted correctly. And please clarify "didn't work" - what happens instead? Your <VirtualHost> definition will need to match with a NameVirtualHost and your existing <VirtualHost>, as well.. –  Shane Madden Jan 15 '12 at 2:11
    
Okay I modified my question for you, thanks for your help. –  EpicOfChaos Jan 15 '12 at 2:24
    
(re: forum image problem) Your proxy configuration is removing /forum from the path - check the HTML source in your browser, it's likely that it has the /forum path hardcoded. –  Shane Madden Jan 15 '12 at 3:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.