I have a requirement as to have a single server with both a Java application and a PHP application, running on the same Apache. Is this possible?
This question may be very silly but I have no clue about java requirements or installation procedures.
Can I do such a thing that as to have the java application running on one port and the PHP application on another port, both on the same Apache?
Yes you can do that. Essentially you have to run the Apache (+ PHP) server on one port and the Tomcat server on a different port.
You can expose the 2nd port to the outside world, and have your URLs use either port 80 for Apache / PHP or (say) 8080 for the Java server. This simple, but you may find that upstream firewalls prevent a remote web browser from connecting to any port other than 80.
You can configure your Apache server as a reverse proxy for the Java server. So for instance, the Apache server might recognize that http://site.com/javaapp/foo.html is for the Java server, and relay requests for that URL to http://localhost:8080/javaapp/foo.html.
There is a whole chapter of the Apache documentation about configuring forward and reverse proxies using mod_proxy.
Yes.
Apache HTTPd can delegate to Apache Tomcat using ModProxy or ModAJP, and can be configured to do so based on the domain, path or file extension requested. Your Apache HTTPd configuration of PHP would remain the same.
You would need to configure Apache Tomcat to not listen on port 80, and then configure the Apache HTTPd proxying solution of your choice to talk to Tomcat on a different port.
Here's a starting point for more information: Apache + Tomcat: Using mod_proxy instead of AJP
This is possible using Apache Reverse Proxy,
I configured one Apache virtual host that serves one PHP website (Drupal) and one java (tomcat, for business logic) that are stored in the same server using a reverse proxy with 2 locations, the advantage of this configuration is that it doesn't expose the port that Tomcat is using on the URL which was mandatory for me for security reasons.
This is how I achieved this:
<VirtualHost *:80>
ProxyPreserveHost On
DocumentRoot "/srv/www/htdocs/"
ErrorLog /var/log/httpd/app_error_log.log
CustomLog /var/log/httpd/app_log.log combined
ServerName myapp.com
#Drupal PHP Content, stored at / as the main front end website.
<Location />
ProxyPass http://localhost/
ProxyPassReverse http://localhost
Order allow,deny
Allow from all
</Location>
#Tomcat/java content, secondary site used to process payments and business logic:
<Location /javaApp>
ProxyPass http://localhost:8080/javaApp/
ProxyPassReverse http://localhost:8080/javaApp/
Order allow,deny
Allow from all
</Location>
</VirtualHost>
Restart Apache:
service httpd restart;
Test your reverse proxies:
PHP/Drupal (In my case i'm using drupal but can be any PHP code):
http://yourserverip/ or http://localhost/
Java:
http://yourserverip/javaApp or http://localhost/javaApp
I hope someone can find this useful.
I had a hard time trying to figure this out. :)
Regards.
Can a sinle apache server handle both tomcat and php?
Yes, you need both apache and tomcat installed, but you can configure apache to redirect (transparently for the user) all JSP requests to tomcat using AJP protocol.
See more here:
http://www.datadisk.co.uk/html_docs/java_app/tomcat6/tomcat6_apache_server.htm
Related
I have remote server with one IP adress, where i having java and php projects. PHP project working with Vesta CP and java projects work with Tomcat 9. I have several domains and subdomains for my java projects, but i do not know how bind my subdomains with my java projects.
For example, i want joining this subdomain diagram.mathzilla.org with my project, which is available by adress and port http://78.24.217.121:8085/MZDiagram/.
How can I do it?
You can't bind two different servers (Apache Tomcat and Apache httpd) to same IP & port. But you can use mod_rewrite for Apache httpd for redirect some queries to other port inside server.
For example:
Tomcat is running on port 8085 and httpd is on port 80. In httpd for virtual host diagram.mathzilla.org you can redirect all queries to port 8085 via .htaccess file:
RewriteEngine on
RewriteRule ^(.*)$ http://localhost:8085/$1 [P]
I just migrated the application from an aged Tomcat server (6.x) to Tomcat 8.
Master: Apache http server
Slave: Apache Tomcat application server
I use the ProxyPass setting to connect the Apache http server to the Tomcat server.
Works well, except the Tomcat server does not maintain httpSession between two httpServletRequests. The second request is suppost to pick-up some values from the httpSession, but the session is new.
Using the Tomcat server on it's own (port 8080) session is maintained between two requests.
I know there is a trick to this, but I'm unable to find it, regardless how many times I'm reading up and down the Apache manual.
httpd-ajp.conf: ProxyPass /MY_APP ajp://127.0.0.1:8009/MY_APP
Any help would be appreciated.
I have a java application running on a server IP 1.1.1.1 port 111
I have an Apache server running on IP 1.1.1.2 port 80
Apache should be configured as a proxy.
Clients will configure their computers to point to my Apache proxy at 1.1.1.2 port 80
The question is could i configure the Apache server to redirect the requests coming from the client to the java app for processing and if the java app sees that it should deny the request then it will inform Apache and Apache by its turn should informs the client.
Am i dreaming or this could be implemented?
Any suggestions would be very helpful
Yes, this is possible. Have a look at the mod_proxy plugin for Apache. There are a few security and implementation considerations to cover, such as:
Is the site to be accessed via a new virtual host defined in Apache, or an existing one?
HTTP vs HTTPs access? (From your post, it seems like the decision is to use HTTP port 80)
What URL(s) to match on for the proxy rule to trigger?
Is the access allowed from all IP ranges or only a particular subnet?
Is there a benefit in offloading some of the static resources to the Apache server to ease the load on the backend application server, or using a mod_deflate to gzip the resources before forwarding them to the clients?
mod_proxy documentation
Tomcat is running in my localhost on standard 8080 port. When tomcat calls a service (soap/rest) running in the same server, I would like to capture it through fiddler.
Basically, any request that tomcat sends out, should be captured through Fiddler. Currently, it sends out request to another service running the same machine and that service in turn calls Amazon AWS, which I would like to capture as well.
Can anyone help? Note that this is opposite of traditional web request through proxy to the server.
I am open to any other alternatives as well.
Please have a look at How to capture SOAP messages from a Tomcat Java app to an external server? for information on setting the proxy for Tomcat.
The correct JVM parameters should look like: -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=8888 -DproxySet=true -DproxyHost=127.0.0.1 -DproxyPort=8888
I'm trying to setup a Solaris KSSL proxy (http://www.c0t0d0s0.org/archives/5575-Less-known-Solaris-Features-kssl.html) as a frontend to a Jetty web server.
I'm able to make KSSL work with Apache web server so that KSSL redirects all incoming SSL traffic from port 443 into an Apache web server listening on port 28080.
However the same configuration does not work when Jetty is listening on port 28080. I verified that the KSSL requests does not even reach Jetty or at least I cannot see them in the access log. Furthermore even if I set a simple Java class which just listens on a server socket, KSSL cannot redirect requests to it.
My question is what are the pre-requisites from a web server in order to be able to get requests from KSSL ?
Best regards,
Lior
There are 2 very common gotchas when working with kssl.
The first is that the apache listening IP has to be the same
as your ksslcfg command. So if you have Listen 123.123.123.123:28080 in
the httpd.conf file, then you must use a ksslcfg command with the same IP.
You cannot have it listening on ANY (*) and then list an IP in ksslcfg,
or listen on an IP and leave out the IP on ksslcfg. Whatever netstat shows
is listening on port 28080 must match the IP used in ksslcfg
(or don't use the IP it is listening on *)
The second is that you must do the operations in this order:
ksslcfg
restart apache
It doesn't not work if ksslcfg is run without restarting apache afterward.
I've seen many people on the web testing with something like
localhost in their ksslcfg command. It won't work unless you also
had localhost as the Listen IP in the apache configuration.