I'm in the process of breaking apart and migrating an apache internal webserver to an IIS web server.
I believe what the snippet of apache web config does below when testing is re-direct any requests coming in from "bobby" to http://localhost:8181/
bobby is a DNS entry on our domain which resolves to 192.168.8.50.
In short, if you place bobby/ into a web browser on our domain without the port specified the below will forward to local host with the correct port.
How can I replicate this in IIS?
<VirtualHost 192.168.8.50:80>
ServerName bobby
ProxyRequests Off
ProxyVia Off
<Proxy *>
Require all granted
</Proxy>
ProxyPass / http://localhost:8181/
ProxyPassReverse / http://localhost:8181/
</VirtualHost>
Do you mean you want to redirect all the request from the "bobby" to "http://localhost:8181/"?
If this is your requirement , I suggest you could try to use IIS url rewrite module IIS reverse proxy to achieve your requirement.
You could install it from this url.
Then you could add below config settings in the bobby web.config file in system.webServer tag.
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://localhost:8181/{R:1}" />
</rule>
</rules>
</rewrite>
Related
I have deployed my Angular2 web application in AWS tomcat server which runs in 8080 port. I have my spring boot backend application deployed in the same tomcat server.
Already mapped my public address with my registered domain in Godaddy.
Now I can access my application appln by http://example.com:8080/my_client
I want to access it directly by http://example.com. dnt want to see 8080 port and appln name in the url.
Already tried with apache proxy config. However not able to get the expected one.
There are 2 options
1) change tomcat port from 8080 to 80 ( not recommended ).
nano tomcat_dir/conf/server.xml
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
2) use apache virtual host config.
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName example.com
ProxyPass http://example.com http://localhost:8080/example
ProxyPassReverse http://example.com http://localhost:8080/example
</VirtualHost>
I'm using Wildfly 9.0.1.Final with single-sign-on to secure my backend and frontend with the following configuration:
<subsystem xmlns="urn:jboss:domain:undertow:2.0">
<server name="default-server">
<http-listener name="default" socket-binding="http" redirect-socket="https"/>
<host name="default-host" alias="localhost">
<location name="/" handler="welcome-content"/>
<filter-ref name="server-header"/>
<filter-ref name="x-powered-by-header"/>
<single-sign-on path="/"/>
</host>
</server>
...
In my development environment, everything is working fine. But if I use FORM login in production environment, where the wildfly is behind an apache server, clients only get JSESSIONID but no JSESSIONIDSSO.
The corresponding apache config is:
ProxyPass /user http://localhost:10080/user
ProxyPassReverse /user http://localhost:10080/user
ProxyPass /backend http://localhost:10080/backend
ProxyPassReverse /backend http://localhost:10080/backend
What could be the problem?
This could be happening because of couple of reasons:
The domain name on the cookie will be reflecting the wildfly domain,
which will be different than the actual domain, which is being used
by the client.
and OR
The path which is set on the cookie is different from the path from where the reverse proxy call being made.
In any of the above case the Set-Cookie header will be received by the browser, its just that it will silently discard it.
You can add the following extra configuration in Apache to solve the issue
ProxyPassReverseCookiePath /example.com /
ProxyPassReverseCookieDomain localhost example.com
Please refer to the Apache documentation for more details and check the error logs for Warning regarding cookies
I have a web application running in Tomcat 8. I can access this application by opening http://subdomain.domain.com:8080/MYAPP.
Now I want to only enter http://subdomain.domain.com to open this application.
How do I have to configure my Apache 2 or Tomcat 8 to achieve this?
See my answer there for more details.
https://stackoverflow.com/a/26305876/1935128
But basically, you need mod_proxy and maybe mod_proxy_connect enabled on apache with a proper virtualhost configuration on apache side. And on Tomcat's side it may work without any modification but you should add proxyName="subdomain.domain.com, proxyPort="80" and scheme="http"
Tomcat connector :
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443"
<!-- This is the important part -->
proxyName="subdomain.domain.com" proxyPort="80"/>
Apache virtualhost:
<VirtualHost subdomain.mydomain.com:80>
ServerName http://subdomain.mydomain.com
# I think these two are optional, depending on the app your run on Tomcat
#ProxyRequests Off
#ProxyPreserveHost On
ProxyPass / http://your.tomcat.server:8080/MYAPP/
ProxyPassReverse / http://your.tomcat.server:8080/MYAPP/
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
</VirtualHost>
I now have one Apache server and two Tomcat servers. They are connected using mod_jk module. And the load balancing is configured. All request will be redirected to the loadbalancer, in httpd.conf:
JKMount /* controller
The controller is the loadbalancer, and the working tomcat servers are worker1, worker2.
The problem is that, in addition to the automatic load dispatch, I also need a url matching redirection. Speicifically, the request for http://www.example.com/test1/index.html should go to worker1 (Tomcat), and http://www.example.com/test2/index.html go to worker2.
However, in both worker1 and worker2, the application structure is webapps/test/ structure.
I can use the mod_jk url mapping to dispatch /test1/ to worker1 and /test2/ to worker2, but the PATH will be /test1/ and /test2/ not /test/. Meanwhile, if I use the apache redirectMatch or url rewrite to change the /test1/(/test2/) to /test/, the mod_jk will not dispatch the url to the different worker now, since they have the same PATH.
How can I deal with this situation?
You need to make the application a root application in Tomcat. You can do this by adding a META-INF/context.xml to your app with the following:
<Context path="/"/>
I'd suggest you remove other apps from the webapps directory. Then you need to alter your apps web.xml so the servlet(s) are now mapped to the appropriate url with the appropriate contexts:
<servlet-mapping>
<servlet-name>TestApp</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>TestApp</servlet-name>
<url-pattern>/test1</url-pattern>
</servlet-mapping>
The app in the second JVM would need the url-pattern /test2 instead. For Apache/Tomcat connection I use mod_ajp rather than mod_jk. Here is what you'd need in Apache for mod_ajp:
<Proxy balancer://cluster>
BalancerMember ajp://127.0.0.1:8015 route=ajp13_node1
BalancerMember ajp://127.0.0.1:8016 route=ajp13_node2
</Proxy>
<Location "/test">
ProxyPass balancer://cluster/test stickysession=JSESSIONID
</Location>
<Location "/test1">
ProxyPass ajp://127.0.0.1:8015/test1
</Location>
<Location "/test2">
ProxyPass ajp://127.0.0.1:8016/test2
</Location>
This is assuming the AJP connector is listening on 8015 for the first JVM and 8016 for the second.
Perhaps a simple way to do it is to use urlrewrite filter on tomcat workers. According to documantation you should have the following rule on your urlrewrite.xml file:
<rule>
<from>^/test[0-9]*/(.*)$</from>
<to type="redirect">/$1</to>
</rule>
So workers would ignore the test1 or test2 URI part. And apache could work just the way you planned with mod_jk.
I have multiple Tomcat servers. In each tomcat I am loading all images. I want to move the images from Tomcat to Apache and access the images from there.
My question is: is there any configuration to get the images in a Java web application from Apache instead of Tomcat?
I don't think so - images are shown by resolving their URL, and in most cases it is relative to the current page.
But you can use mod_proxy (or mod_jk) to use all your tomcats through Apache.
Hide your tomcat servers behind an apache server and then you can do something like this:
<VirtualHost www.example.com:80>
ServerName www.example.com
DocumentRoot /var/www/html
ProxyPass /img !
ProxyPass / ajp://localhost:1234/
</VirtualHost>
Apache will serve /img from /var/www/html/img and other requests will be sent to tomcat. This configuration needs mod_proxy_ajp apache module to be active. Tomcat must listen to AJP requests on the given port, use:
<Connector port="1234" protocol="AJP/1.3" redirectPort="8443" address="127.0.0.1" URIEncoding="UTF-8" />
And configure tomcat to serve www.example.com or the default virtual host.
<Host
name="www.example.com"
appBase="/path/to/tomcat/apps/www.example.com"
unpackWARs="true"
autoDeploy="true"
xmlValidation="false"
xmlNamespaceAware="false"
/>
or
<Host
name="localhost"
appBase="/path/to/tomcat/apps/www.example.com"
unpackWARs="true"
autoDeploy="true"
xmlValidation="false"
xmlNamespaceAware="false"
/>
Deploy your webapp to /path/to/tomcat/apps/www.example.com/ as ROOT.war, this should be enough to have the whole setup up and running.