Sending emails behind firewall using Apache - java

I've got one Debian server with access to the Internet and Apache installed on it, and it can connect to email server by static IP.
There is the second Debian server behind firewall without access to the Internet and Java application on it, it can connect ot the first server only.
Can I configure apache such as it listens to port (for example 8081) and redirects it to mail server in order to send email messages on second server?
I tried this:
1) configure second server to send email to the first server using port 8081 (not 25).
2) add new port in /etc/apache2/ports.conf and to add new VirtualHost as described below.
<VirtualHost "*:8081">
#VirtualHost for email server
ProxyRequests On
ProxyPass / http://mail_server_ip:25/
ProxyPassReverse / http://mail_server_ip:25/
<Location />
Order Deny,Allow
Allow from all
</Location>
</VirtualHost>
But nothing meaningful happens, only SocketTimeoutException and javax.mail.MessagingException: Exception reading response.
Is Apache suitable for this task? Is there any way to do it properly?

Related

how to access java web application with ip address without entry the port

I'm using glassfish 4.1 server with port 8080.
my apps can access by hit localhost:8080 or using my_ip_address:8080.
now, I want access my apps only with ip address without entry the port, say my ip is 10.1.2.133, so when I hit 10.1.2.133 it's go to my apps.
how to do it?
I've tried changing the port to 80 and it worked so well. but I still want to use port 8080 instead 80.
I've tried changing the port to 80 and it worked so well. but I still want to use port 8080 instead 80.
Port 80 is the only default port that web browsers understand for the HTTP protocol.
If you want to use a different port (8080) for your server, you must either:
use port 8080 in the URL
set up another server on port 80 that will either redirect requests to port 8080, or reverse proxy the requests to port 8080.
Redirection works by having the server on port 80 send HTTP 3xx responses that tell user's the browser to resend the request to the URL for the port 8080 server.
Reverse proxying works by the server on port 80, sending the request to the port 8080 server itself, and then relaying the response.
You could consider using a reverse proxy like apache httpd or HAProxy in front your application. Configure them to listen to port 80 and redirect requests based on the context to your application at 8080
Take a look at::
https://www.digitalocean.com/community/tutorials/how-to-use-apache-http-server-as-reverse-proxy-using-mod_proxy-extension
https://github.com/foosel/OctoPrint/wiki/Reverse-proxy-configuration-examples
https://dzone.com/articles/how-to-configure-ha-proxy-as-a-proxy-and-loadbalan
The default Http port is 80, and therefore if your app run at 80 you can omit it, in other cases you must specify the port. Else you must have a Proxy server listen at 80 and re-direct it to the required server based on context( read path ) or some-other information.
You can run another server that points to your server on 8080. Your other server would then be running on port 80 as this is the default port.
Config on Apache would be something like this:
<VirtualHost *:80>
ServerName sample.com
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://YOUR_IP_HERE:8080/
ProxyPassReverse / http://YOUR_IP_HERE:8080/
RewriteEngine On
<!--other config here-->
</VirtualHost>

SSL sharing between Apache and Apache tomcat with standard port

I have a wordpress application deployed on an Apache server running on port 80 and I also have a java web application deployed on a Tomact server running on port 443.
So basically I have:
http ://mysite.com (Apache)
https: //mysite.com/application (Tomcat)
Now I need to start using my SSL certificate for my website. I know that these processes cannot share the same port. Is there a way to keep both urls without adding an extra port? So both can be accessed via:
https ://mysite.com (Apache)
https ://mysite.com/application (Tomcat)
I'm basing this answer on my configuration with Apache in the front of a Tomcat instance. I don't have your exact configuration but I believe the following should work.
I have an SSL configuration which is where things get forwarded to Tomcat.
I've modified it to be what I think you need:
<VirtualHost _default_:443>
ServerName www.example.com
ProxyPreserveHost on
ProxyPass /application http://localhost:8080/application
ProxyTimeout 360
# rest of the ssl configuration
</VirtualHost>
This should forward everything under /application to Tomcat and keep the rest being served by Apache. Note that this assumes that you have the proxy (a.k.a. mod_proxy) module enabled for your server.
An easy way of doing this is to mount an Nginx server and manage the redirection according to the URL hit:
server {
listen 80;
server_name *.domain.me;
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name *.domain.me;
ssl_certificate /path/to/crt;
ssl_certificate_key /path/to/key;
location / {
proxy_pass http://destinationIp:destinationPort;
proxy_set_header Host $host;
}
}

Access Oracle Http server(OHS) in a LAN

I have configured OHS server infront of Weblogic to forward all request from OHS to WL server and it's working fine in local machine(where both WL and OHS are installed) and I could access the application deployed on WebLogic using OHS port.
http://localhost:OHS_port/MyApp/,
http://host_IP:OHS_port/MyApp/ and
http://127.0.0.1:OHS_port/MyApp/
all these url's working fine in the same machine where OHS and weblogic servers are deployed.
But when I try to access the same in LAN using OHS server port ,I am unable to access the application(http://host_IP:OHS_port/MyApp/), but same is accessible using weblogic port(http://host_IP:WL_port/MyApp/).
httpd.conf -
Listen 7777
ServerName 10.0.0.10:7777
(Rest of details in this files are default values)
mod_wl_ohs.conf -
<IfModule weblogic_module>
<Location /MyApp>
WLSRequest On
WebLogicHost 10.0.0.10
WeblogicPort 7001
</Location>
</IfModule>
Any idea why I am unable to access with OHS port? Is this something to do with firewall? If firewall issue, how I am able to access with weblogic port and not with OHS(I tried exchanging OHS and WL port and still the behavious is same(works with new weblogic port but not with OHS port)).
Thanks
Your ServerName value should be the host name that you want OHS to respond on or the LAN IP address.
For instance, if the IP address of the machine is 10.1.1.10 and the hostname is myohs.mydomain.com, use the following:
ServerName myohs.mydomain.com
Also, be sure DNS is mapping myohs.mydomain.com to 10.1.1.10.

Multi-tenancy on tomcat

I've set of JSON APIs that are exposed and implemented on Tomcat.
I would like to implement Multi-tenancy for these APIs on Tomcat with the following URL approach:
companyname1.domain.com/api/getUsers...
companyname2.domain.com/api/getUsers...
companyname3.domain.com/api/getUsers...
Let me know if there is a best practice for implementing it using context or other mechanism. I don't want to create a separate Tomcat instance for each and every company.
In addition is there any way to create it dynamically once company is registered.
Thank you in advance,
Moshe
Create several virtual hosts in your Tomcats server.xml, that listen to your domains. These should point to different webapps directories, hosting your particular application in the ROOT directory:
<Host name="localhost" appBase="domain1-webapps" autoDeploy="true" unpackWARs="true"></Host>
<Host name="companyname1.domain.com" appBase="domain1-webapps" autoDeploy="true" unpackWARs="true"></Host>
<Host name="companyname2.domain.com" appBase="domain2-webapps" autoDeploy="true" unpackWARs="true"></Host>
...
This can be done using multiple reverse proxies that provide different parameters to the Tomcat webapp. The simplest setup (with Apache HTTP and mod_proxy_ajp) would probably be to preserve the original request's host and resolve that inside the web app.
<VirtualHost *:80>
ServerName companyname1.domain.com
ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
ProxyPreserveHost On
</VirtualHost>
<VirtualHost *:80>
ServerName companyname2.domain.com
ProxyPass /api ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
ProxyPreserveHost On
</VirtualHost>
<VirtualHost *:80>
ServerName companyname3.domain.com
ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
ProxyPreserveHost On
</VirtualHost>
I can not comment because of my reputation is below than 50.
if URI is same like
companyname1.domain.com/api/getUsers
companyname2.domain.com/api/getUsers
companyname3.domain.com/api/getUsers
then Apache web server found domain companyname1.domain.com and from httpd file, it send call to tomcat application server through AJP connector. But problem is that how can it found which war file to run.
So application name is required in URL
companyname1.domain.com/abc/api/getUsers
companyname2.domain.com/xyz/api/getUsers
companyname3.domain.com/fgf/api/getUsers
We can use server context setting. As per tomcat server specification.
The Host element represents a virtual host, which is an association of a network name for a server (such as "www.mycompany.com")
with the particular server on which Tomcat is running. For clients to be able to connect to a Tomcat server using its network name,
this name must be registered in the Domain Name Service (DNS) server that manages the Internet domain you belong to - contact your Network Administrator
for more information.
In many cases, System Administrators wish to associate more than one network name (such as www.mycompany.com and company.com)
with the same virtual host and applications. This can be accomplished using the Host Name Aliases feature discussed below.
One or more Host elements are nested inside an Engine element.
Inside the Host element, you can nest Context elements for the web applications associated with this virtual host.
Exactly one of the Hosts associated with each Engine MUST have a name matching the defaultHost attribute of that Engine.
Clients normally use host names to identify the server they wish to connect to. This host name is also included in the HTTP request headers.
Tomcat extracts the host name from the HTTP headers and looks for a Host with a matching name.
If no match is found, the request is routed to the default host.
The name of the default host does not have to match a DNS name (although it can) since any request where the
DNS name does not match the name of a Host element will be routed to the default host.
For more info. go through this link.
:https://tomcat.apache.org/tomcat-8.0-doc/config/host.html

How to get VHost Server Name with Java?

Hello Stackoverflow Community,
i'm getting a bit confused with getting the Servername of a Vhost. Im working with my apache and a Tomcat. The Apache is redirecting the Requests to my Tomcat to start a Function.
The Point is that i have to identify the Servername. The purpose is to get the Servername and decide like if the servername is like office23.de then the server has to load the configuration for office23 if other office then load other configurations. I hope i could explain it a bit.
What i did so far:
i added into Tomcat's server.xml :
also added in Apache's httpd.conf:
ProxyRequests on
ProxyPass /getTest/ http://localhost:8080/Test/
ProxyPassReverse /getTest/ http://localhost:8080/test/
and the lines to load the mod_proxy stuff.
additional i configured the httpd-vhosts.conf like this:
ServerName js.local.test.de
DocumentRoot "D:/downloads/xampp/tomcat/webapps"
<Directory />
Require all granted
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog "D:/downloads/xampp/apache/logs/virtualHost.log"
CustomLog "D:/downloads/xampp/apache/logs/customLog.log" common
i can reach my application through the vhost adress but when i try to get the Host Header it says that its localhost:8080.
I also changed the windows hostfile.
Does any opurtunity excist that allows me to get the vhost name?
If you enable ProxyPreserveHost on the reverse proxy, the Host: header is kept in the request to the proxy, instead of being replaced with the hostname specified in the ProxyPass (localhost, in your case). That should help you get the right name on the back-end.
Mangling the hosts file won't do you any good, and if you forget you did that, it'll probably come back to haunt you, later on.

Categories

Resources