Apache HTTP Server reverse proxying from port 80 to port * - apache

I have a Suse Linux server with a web application listening on Port 51058.
I want now to use Apache HTTP Server to forward the user from port 80 to this port so that when the user types the url in the Browser the user sees the application on port 51058.
I do not want to use redirection because i must open then also the port 51058. Is it possible to do something like this with Apache HTTP Server?
If yes how can I do this?

You will need to setup a reverse proxy with Apache using the mod_proxy module.
You may use something like this a Virtual Host for port 80:
<VirtualHost *:80>
ServerName MyServerHostName
ProxyPreserveHost On
ProxyRequests Off
ProxyPass / http://localhost:51058/
ProxyPassReverse / http://localhost:51058/
</VirtualHost>
Here I assume that 51058 is a non-secure(HTTP) port.

You can change the Listen port from 51058 to 80 and configure the Virtual host to use port 80

Related

Two Domains, One Apache Server. One Tomcat Server. How do I configure Apache to redirect one doamin to Tomcat?

I have two domains domainA.com and domainB.com that both point to the same IP address/server. On that server...
I have an Apache2 web server serving port 80
I have a TomCat9 serving port 8080
I want to redirect all requests (including "/") to the default port 80 of domainB.com to the TomCat9 server on port 8080, whilst leaving all traffic to domainA.com to be handled by the Apache2 web server.
Can anyone recommend a simple recipe for achieving this?
I have looked at https://tomcat.apache.org/tomcat-4.1-doc/proxy-howto.html but got somewhat lost.
May have been easier than I had expected.
I just added the following to /etc/apache2/sites-enabled/donainB.conf
<VirtualHost *:80>
ServerAdmin michael.ellis#myemail
ServerName domainB.com
ProxyPass / http://localhost:8080/
</VirtualHost>
I have no idea if this is the correct thing to do, but it seems to be doing the job.

How do I setup an Apache ProxyPass / Reverse Proxy while listening on an alternate port?

I had Apache configuration which was using a ProxyPass/ProxyPassReverse with the following example syntax:
ProxyPass /myprog http://localhost:8080/myprog
ProxyPassReverse /myprog http://localhost:8080/myprog
Then, I moved Apache from port 80, to 8880, and put another web server on port 80. I can access some things correctly now on port 8880 - those files which are hosted directly on Apache. But my proxy pass (to Tomcat) now fails when I try to access it at: http://some.domain:8880/myprog.
How do I correct the ProxyPass/Reseverse to account for the port change? (I assumed, perhaps natively, the port spec was implicit...).
You need to put your configuration on a VirtualHost tag.
<VirtualHost *:8880>
ProxyPreserveHost On
ProxyRequests Off
ProxyPass /myprog http://localhost:8080/myprog
ProxyPassReverse /myprog http://localhost:8080/myprog
</VirtualHost>

Apache 2.4 reverse proxy

I have devserver on intranet with ubuntu, apache 2.4. There is some service running on direct ports like yourtrack on port 9000.
When I connecting directly its working properly (http://devserver:9000/).
But I want to make on this format. http://devserver/yourtrack
How could I do this?
You could use apache proxying to your application. So you declare the port 80 virtual host and the use proxy pass to proxy to the other port.
<VirtualHost *:80>
ServerName devserver
ProxyPreserveHost On
ProxyPass /yourtrack http://devserver:9000/
ProxyPassReverse /yourtrack http://devserver:9000/
</VirtualHost>
WARNING: This could have adverse effect on the application you're running depending what it does with http requests.

EC2 SSL not working

I'm running an EC2 micro instance (Amazon Linux) and can't seem to get ssl (https) working.
The error I'm getting in Chrome is "ERR_CONNECTION_REFUSED" (no data sent).
I've enabled HTTPS inbound traffic for the security group in my AWS console.
I added this in the /etc/httpd/conf/httpd.conf file. (example.com is a placeholder for my website)
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
SSLEngine on
SSLCertificateFile /etc/ssl/example_com.crt
SSLCertificateKeyFile /etc/ssl/example_com.key
SSLCertificateChainFile /etc/ssl/example_com.ca-bundle
</VirtualHost>
and it didn't work.
So to test VirtualHost, I replaced it with the following:
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://google.com/
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
Redirect permanent / https://google.com/
</VirtualHost>
http://example.com redirected to google like expected, but https://example.com didn't.
Anyone know what's the problem?
Connection refused means your server's IP stack actively rejected the incoming connection on port 443 (https) because no service is listening on port 443.
We use less and less Apache these days in my operations, because of the maturity of some other alternatives, so I may be a little rusty here, but I'm reasonably sure that your server, in spite of being configured with a way to respond to requests on port 443... is not actually listening for connections on port 443.
You probably have a listen 80 somewhere in your apache config. This will need to be accompanied by listen 443 based on httpd.apache.org/docs/2.2/bind.html:
When Apache starts, it binds to some port and address on the local machine and waits for incoming requests. By default, it listens to all addresses on the machine. However, it may need to be told to listen on specific ports, or only on selected addresses, or a combination of both. This is often combined with the Virtual Host feature, which determines how Apache responds to different IP addresses, hostnames and ports.
In addition to configuring the security group to allow the traffic over port 443, you probably also need to open port 443 on the server itself.
iptables -I INPUT 1 -p tcp --dport 443 -j ACCEPT
If that fixes the issue, then to save the configuration so that it persists after a reboot:
/sbin/service iptables save

Apache named vhost not catching requests that should go to it

I have an Apache server with a group of name-based virtual hosts on it. Requests are sent to the server via an Apache reverse proxy, which forwards all requests for these site names to port 80 on the backend server. While most of these sites appear to be working fine, one vhost is failing to pick up requests for its designated site name, and these are instead being served by the default vhost.
Here's the configuration for the problematic host:
<VirtualHost *:80>
ServerName www.dev.awesome.ac.nz
ServerAdmin netaccount#auckland.ac.nz
ErrorLog logs/awesomeacnz.error.log
CustomLog logs/awesomeacnz.access.log common
Alias / /var/www/html/awesomeacnz/
</VirtualHost>
And here's the output of the Apache vhost diagnostic:
[aful018#wprappdev01 ~]$ sudo /usr/sbin/apachectl -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
_default_:443 wprappdev01.its.auckland.ac.nz (/etc/httpd/conf.d/ssl.conf:74)
*:80 is a NameVirtualHost
default server asblog.auckland.ac.nz (/etc/httpd/conf.d/academicservices.conf:1)
port 80 namevhost asblog.auckland.ac.nz (/etc/httpd/conf.d/academicservices.conf:1)
port 80 namevhost www.dev.awesome.ac.nz (/etc/httpd/conf.d/awesomeacnz.conf:1)
port 80 namevhost www.dev.auckland.ac.nz (/etc/httpd/conf.d/insideword.conf:1)
port 80 namevhost spearblog.dev.auckland.ac.nz (/etc/httpd/conf.d/spear.conf:1)
port 80 namevhost wordpress-theme.dev.auckland.ac.nz (/etc/httpd/conf.d/theme-dev.conf:1)
Syntax OK
I can't see anything in the above that suggests a problem, but when I send a request for anything on www.dev.awesome.ac.nz the request is served by the vhost for asblog.auckland.ac.nz, which as you can see above is the default host.
Does anyone know why the vhost defined above would not be matching requests for that site? The NameVirtualHost directive in httpd.conf is set to *:80, and other similarly- (not identically-) configured sites on the same server are working fine.
The server is apache 2.2.15 running on Red Hat EL 6.1.