Need urlrewrite for proxypass enabled server - apache

I have a application deployed in tomcat(app1), front end by appache web server. So if i hit onlinetamilportal.com then it will point to onlinetamilportal.com:8080/app1. Which is working fine.
What i want is url rewrite, www.onlinetamilportal.com/showPost.jsp?serial=deivamagal should rewrite www.onlinetamilportal.com/serial/deivamagal. how to acheive this? Tried lot of rewrite rule for the past 4-5 days. Any help will be appreciated.
<VirtualHost *:80>
ServerName www.onlinetamilportal.com
ProxyPass / ajp://127.0.0.1:8009/app1/ smax=0 ttl=60 retry=5
ProxyPassReverse / ajp://127.0.0.1:8009/app1
</VirtualHost>

Related

Gogs.io running on subdomain with port

I'm trying to run Gogs.io on an apache webserver along with a standard website, and I'm trying to have Gogs.io used on a subdomain rather than using my standard domain with a port.
Gogs.io runs on port 3000, and I want the url to be
http://gogs.example.net/
Rather than
http://example.net:3000/
Both my public IP with port and example.net:3000 work, but when trying to use gogs.example.net, I always get an AT&T DNS Error Assist page. I'm not sure what I'm doing wrong, as I had it working earlier until I tried to change the name of the subdomain in my apache config, but I changed it back when I started having issues, to no luck.
Here is my Apache config for the page:
<VirtualHost *:80>
ServerName gogs.example.net
ProxyPreserveHost On
ProxyPass / http://example.net:3000/
ProxyPassReverse / http://example.net:3000/
</VirtualHost>
This may be impossible, but any help would be greatly appreciated!
Fixed the issue by adding an A record to my domain
A Record: git -> 111.222.333.444
As well as modified the VirtualHost settings to include the subdomain in the ProxyPass and ProxyPassReverse
<VirtualHost *:80>
ServerName gogs.example.net
ProxyPreserveHost On
ProxyPass / http://git.example.net:3000/
ProxyPassReverse / http://git.example.net:3000/
</VirtualHost>

Apache Reverse Proxy Cookies not working

following scenario:
I have a webservice running on port 81.
I want to use apache(nginx would also be okay) as reverse proxy, running on port 80 and redirecting mail.domain.com to port 81.
This is working so far.. but my webservice is telling me, that i should activate cookies. Without proxy it's working.
I followed a lot of tutorials etc., but none of the tips worked so far.
This is how my virtualhost looks:
<virtualHost *:80>
ProxyPassReverseCookiePath / http://mail.domain.com
ServerName mail.domain.com:81
ProxyPass / http://127.0.0.1:81
ProxyPassReverse / http://127.0.0.1:81
ProxyPassReverseCookiePath http://myPublicIp:81 http://mail.domain.com
</VirtualHost>
If someone has an easier way with nginx doing this, pls also tell me.
Thanks a lot in advance!!
You probably need to do something like this:
<VirtualHost *:80>
ServerName mydomain.com
ProxyPass / http://mail.domain.com:81
ProxyPassReverse / http://mail.domain.com:81
ProxyPassReverseCookieDomain mydomain.com mail.domain.com
</VirtualHost>
In your example, you are using the CookiePath which is modify the path in the cookie and not the domain.

Apache 2.2 and tomcat redirection for subdomains

I have two tomcat servers running in my machine and i want to use apache to redirect the traffic to each server depending on the subdomain.
My httpd.conf is:
<VirtualHost *:80>
ServerName dev.bo.example.com
ProxyPass / ajp://localhost:11009/bo/
ProxyPassReverse / ajp://localhost:11009/bo/
ProxyPassReverseCookiePath /bo/ http://localhost:11001/bo/
</VirtualHost>
<VirtualHost *:80>
ServerName dev.com.example.com
ProxyPass / ajp://localhost:10009/com/
ProxyPassReverse / ajp://localhost:10009/com/
ProxyPassReverseCookiePath /com/ http://localhost:10001/com/
</VirtualHost>
The problem is that the traffic is always direct to the first tomcat server despite the subdomain i use.
It seems that only the first virtual host match despite if i use:
http://dev.com.com.example.com/ or
http://dev.bo.example.com/
Does any know what i am missing here?
Finally, i found that i missed configuration i had to add
NameVirtualHost *:80
to the httpd.conf

Apache in front of Jboss url problems

I am having some problems setting up an Apache Web Server in front of Jboss.
I rent a vps with apache and jboss running up and working fine separately.
Jboss is working fine when I want to acess my app through http://myVpsUrl.com:8080/myApp/
I am trying to redirect http://myUrl.com to my jboss app.
In Apache conf file I set :
<VirtualHost *:80>
ServerName myUrl.com
ServerAlias myUrl.com
ProxyPass / http://localhost:8080/context/
ProxyPassReverse / http://localhost:8080/context/
ProxyPassReverseCookiePath / /
ProxyRequests On
</VirtualHost>
When I am going to myUrl.com I can reach the web app homepage but :
images and style are missing
All links redirect my to the homepage
My style and images are located in
http://myVpsUrl:8080/context/css/icons/devices-14-20.png
http://myVpsUrl:8080/context/javascript/util.js
http://myVpsUrl:8080/context/images/*
etc...
I tried to add
ProxyPreserveHost On
But I'm getting an error :
The page isn't redirecting properly or Infinite redirection
I am stuck with this error since a week, any help would be sincerely appreciated.
Thank you.
I finally find how to make it work.
1- Create a virtual-server in jboss
jboss-as-7.1.1.Final/standalone/configuration/standalone.xml
<virtual-server name="myVirtualServerName" default-web-module="nameOfWarFile">
<alias name="myurl.com"/>
</virtual-server>
2- Configure jboss-web.xml
<jboss-web>
<virtual-host>myVirtualServerName< /virtual-host>
</jboss-web>
3- Restart Jboss and Deploy you app
=> You should be able to access your app via myurl.com:8080
4- Make a redirection from port 80 to 8080 on apache
<VirtualHost *:80>
ServerName myurl.com
ServerAlias www.myurl.com myurl.com
ProxyPass / http://myurl.com:8080/
ProxyPassReverse / http://myurl:8080/
</VirtualHost>
5- Edit your host file (/etc/host) and add this line
127.0.0.1 myurl.com
6- Restart apache, you should be able to access your jboss via myurl.com
you could try use the rewrite engine.
Try this:
<VirtualHost *:80>
ServerName myUrl.com
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://localhost:8080/context/
ProxyPassReverse / http://localhost:8080/context/
RewriteEngine On
RewriteCond %{THE_REQUEST} /context/
RewriteRule ^/context/(.*)$ /$1 [PT]
</VirtualHost>

Apache ProxyPass for URLS inconsistently failing

This one's driving me nuts. I have an active and in-use Apache proxy server serving content up on EC2. It's working great, and has a variety of vhosts that are configured like this:
<VirtualHost *:80>
ServerName m.FOO.com
ServerAlias customer.FOO.com
ProxyPreserveHost On
ProxyPass / ajp://10.211.42.48:8009/
ProxyPassReverse / ajp://10.211.42.48:8009/
<Proxy ajp://10.211.42.48:8009/*>
Order allow,deny
Allow from all
</Proxy>
</VirtualHost>
These all work great, and I'm having no problems. Now what I'd like to do is move it so instead of a single vhost for each app, I want to have a sub-url on the main site that proxies back to the appserver. So instead of a customer having 'customer.FOO.com', they'll have 'FOO.com/customer/'
Great, sounds easy, right? Yeah, not so much. I edit the vhost entry for 'root' of the server (currently showing the landing page), and add the proxy entries to directories within that. That should do it,right? Yeah, it ain't:
<VirtualHost *:80>
ServerName web01.aws.FOO.com
DocumentRoot /var/www/html
ErrorLog logs/www.FOO.com-error_log
CustomLog logs/www.FOO.com-access_log common
<Location /a>
ProxyPass ajp://10.211.42.48:8009
ProxyPassReverse ajp://10.211.42.48:8009
</Location>
<Location /t>
ProxyPass http://adm01
ProxyPassReverse http://adm01
</Location>
<Proxy ajp://10.211.42.48:8009/*>
Order allow,deny
Allow from all
</Proxy>
</VirtualHost>
If i hit http://www.FOO.com/t/ - I get the internal webserver - it proxies forward correctly, and all is well. If I hit http://www.FOO.com/a/ I get a 404 error. The access log even shows a 404 error.
Note that the ProxyPass AJP entries are identical to what's in the other vhost entry. So why does it work on the root on the other vhost entry, and not as a subdir here on the main vhost?
Halp!
I ended up solving this with one particular hint I found out on a mailing list somewhere. The ProxyPassReverse directive is very touchy, and has one basic function. Anything it matches on the second argument (assuming using the ProxyPassReverse A B form) will be applied to the first argument. So it's critical to make sure the second argument is exactly the redirect that is coming from your application, or else the ProxyPassReverse directive will be ignored.
In my case, what I ended up doing was changing the Location entry to:
ProxyPass /a/ ajp://10.211.42.48:8009
ProxyPassReverse /a/ http://my.apphost.com/
And all started working just fine.