logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: ugly url name via reverse proxy
Author
chongster



Joined: 04 Jun 2014
Posts: 9

PostPosted: Wed 04 Jun '14 18:30    Post subject: ugly url name via reverse proxy Reply with quote

Hi, I'm having trouble making the URL look nice.
I have Apache redirecting all request to Tomcat, which is reading jsp, via reverse proxy, but the url is not pretty at all.
This my current setup

<VirtualHost *:80>

ServerName app.example.com
ServerAlias www.dummy-host.example.com

ProxyPass / ajp://localhost:8109/app
RewriteEngine On
RewriteRule /app/(.*)$ /$1 [PT]

ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>

result after typing in app.example.com:
app.example.com/app
Goal:
app.example.com

I've also tried
RewriteRule /app/(.*)$ /$1 [R]
This got me the result I want, but I was not able to login.

Thanks a bunch!
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3092
Location: Hilversum, NL, EU

PostPosted: Wed 04 Jun '14 19:52    Post subject: Reply with quote

Have a look ProxyPassReverse at http://httpd.apache.org/docs/2.2/mod/mod_proxy_ajp.html

There is written:

Note that usually no ProxyPassReverse directive is necessary. The AJP request includes the original host header given to the proxy, and the application server can be expected to generate self-referential headers relative to this host, so no rewriting is necessary.

The main exception is when the URL path on the proxy differs from that on the backend. In this case, a redirect header can be rewritten relative to the original host URL (not the backend ajp:// URL), for example:

Rewriting Proxied Path

ProxyPass /apps/foo ajp://backend.example.com:8009/foo
ProxyPassReverse /apps/foo http://www.example.com/foo

However, it is usually better to deploy the application on the backend server at the same path as the proxy rather than to take this approach.
Back to top
chongster



Joined: 04 Jun 2014
Posts: 9

PostPosted: Wed 04 Jun '14 20:34    Post subject: Reply with quote

Thanks,

Unfortunately when I tried ProxyPass by itself I get a redirect loop error.

When I go to app.example.com, it will automatically add /app at the end...
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3092
Location: Hilversum, NL, EU

PostPosted: Wed 04 Jun '14 20:44    Post subject: Reply with quote

Have a look at last comment at http://stackoverflow.com/questions/19906121/apache-2-x-and-mod-proxy-produce-redirect-loop-if-user-is-not-authenticated
Back to top
chongster



Joined: 04 Jun 2014
Posts: 9

PostPosted: Wed 04 Jun '14 21:05    Post subject: Reply with quote

Thanks Steffen, I tried the last comment, but it is still giving me a redirect loop error.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Thu 05 Jun '14 15:55    Post subject: Reply with quote

Steffen wrote:

ProxyPass /apps/foo ajp://backend.example.com:8009/foo
ProxyPassReverse /apps/foo http://www.example.com/foo

However, it is usually better to deploy the application on the backend server at the same path as the proxy rather than to take this approach.


The path should be identical.

I use something like this for my jenkins
Code:

<VirtualHost *:80>
    ServerName jenkins
    DocumentRoot "/Apache24/htdocs"
    <Directory "/Apache24/htdocs">
        Options Indexes Includes FollowSymLinks
        AllowOverride All
        Order Allow,Deny
        Allow from all
        Deny from none
    </Directory>
    <Location />
        ProxyPass ajp://localhost:8109/app
        ProxyPassReverse ajp://localhost:8109/app
    </Location>
</virtualhost>
Back to top
chongster



Joined: 04 Jun 2014
Posts: 9

PostPosted: Thu 05 Jun '14 17:05    Post subject: Reply with quote

I don't have anything in the DocumentRoot though...
I'm curious on why do you have DocumentRoot and ProxyPass together? Correct me if I'm wrong, from my understanding, the DocumentRoot basically tell apache to look there and read the stuff in there. ProxyPass is like Apache directing the request to other servlet.

P.S. My current situation is very similar to this
Steffen wrote:
http://stackoverflow.com/questions/19906121/apache-2-x-and-mod-proxy-produce-redirect-loop-if-user-is-not-authenticated

unfortunately the solution there didn't quite work out for me...
Back to top


Reply to topic   Topic: ugly url name via reverse proxy View previous topic :: View next topic
Post new topic   Forum Index -> Apache