Apache reverse proxy sometimes takes over all requests - apache

(I am x-posting this from serverfault because I didn't get any responses there and we have a lot apache pros over here)
I am using my apache as a reverse proxy for a few requests to a webserver running on an internal port to allow access via my regular virtual host. This is on an ubuntu 15 running apache 2.4 in vagrant.
Here's my virtualhost config:
<VirtualHost *:80>
DocumentRoot /vagrant/htdocs
ServerName test.vm
# proxy pass mailcatcher to internal webserver
<Location /mailcatcher>
ProxyPass http://localhost:1080
ProxyPassReverse http://localhost:1080
</Location>
<Location /assets>
ProxyPass http://localhost:1080/assets
</Location>
<Location /messages>
ProxyPass ws://localhost:1080/messages
ProxyPassReverse http://localhost:1080
</Location>
<Directory />
Require all granted
</Directory>
<Directory /vagrant/htdocs>
AllowOverride all
</Directory>
</VirtualHost>
For a while, this works fine. However, after a time, suddenly all requests to this virtualhost are proxied to the internal webserver. So if I call http://test.vm/cron/mails.php at first it will run mails.php as expected. However after a random amount of time or event, suddenly the aforementioned URL will start serving responses from Mailcatcher.
The message you were looking for does not exist, or doesn't have content of this type
This is a Mailcatcher error that you get when you request a message that no longer exists.
This service, Mailcatcher, is started with my VM and runs all the time. The weird thing is, I don't experience this issue when I am doing other stuff on the VM (there's a web app running on it). Only when I am actively debugging mails and using the Mailcatcher gui am a I suddenly sometimes experiencing this.
Waiting for a while or restarting apache "solves" this issue until it pops up the next time. Can anyone help me out on this? Did I set up my proxy wrong?
Thanks.

You can try these :
<VirtualHost *:80>
ServerName mailcatcher.domain.tld
ServerAdmin webmaster#domain.tld
<Location />
ProxyPass http://localhost:1080/
ProxyPassReverse http://localhost:1080/
</Location>
<Location /messages>
ProxyPass ws://localhost:1080/messages
ProxyPassReverse ws://localhost:1080/messages
</Location>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Notes :
Of course localhost is set in your /etc/hosts or should be change to your mailcatcher server.
It's better to dedicate a hostname to mailcatcher service. With mod_proxy is not easier to manage correctly sub directory path.

Related

AEM: Using Reverse Proxy - Dispatcher

Could you please let me know how can we use reverse proxy to allow non aem server to post pages to a directory on the main domain on AEM site (Eg: www.yourdomainname.com/test-one)?
I have tried adding the below syntax in the vhost file in dispatcher module of Apache server for using reverse proxy. However, this didn't work and faced a 404 on dispatcher upon server restart. The reason might be dispatcher reverse proxies to the publish instance. How can we bypass this issue to setup reverse proxy?
<VirtualHost *:80>
ServerName www.yourdomainname.com
ProxyRequests off
RemoteIPHeader X-Forwarded-For
Header set xxx-Proxy-Version "1.0"
ProxyPreserveHost On
<Location /test-one >
ProxyPass "http://xxx/test-one"
ProxyPassReverse "http://xxx/test-one"
Order allow,deny
Allow from all
</Location>
<Location /test-one/(.*) >
ProxyPass "http://xxx/test-one/(.*)"
ProxyPassReverse "http://xxx/test-one/(.*)"
Order allow,deny
Allow from all
</Location>
</VirtualHost>
Thanks

Change Apache Guacamole URL Path

I have recently installed Apache Guacamole on my Centos 8 server. When I try to access the server it uses the following url: http://10.10.44.11:8080/guacamole/#/ However, I would like to simplify this URL path to something like http://10.10.44.11/. In other words, no path after the IP Address.
I have spent a lot of time trying to figure out the solution by changing the <Location> path, I have tried all combinations possible but have not succeeded.
I have apache version 2.4.37 (centos) as well as tomcat-9.0.48.
By default /etc/httpd/conf.d/tomcat_manager.conf contains:
<VirtualHost *:80>
ServerAdmin root#localhost
ServerName 10.10.44.11
DefaultType text/html
ProxyRequests off
ProxyPreserveHost On
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
However, I tried to change the variables a bit so it can remove the /path, based on multiple forms to something like:
<VirtualHost *:80>
ServerAdmin root#localhost
ServerName 10.10.44.11
<Location /> #
Order allow,deny
Allow from all
ProxyPass http://localhost:8080/guacamole/ flushpackets=on
ProxyPassReverse http://localhost:8080/guacamole/
</Location>
</VirtualHost>
Where "/" in <Location /> means NO-PATH
The problem is that I have not been able to successfully change the PATH at all... I am not an expert in apache, so perhaps I am doing something wrong?
If it is important: the location of my guacamole.war is at /etc/guacamole
Any help would be greatly appreciated!

Enable PUT and DELETE methods on Apache 2.4

I'd like to enable on my Apache 2.4 under linux the PUT and DELETE methods. When clients try to invoke such methods I get a "405 Method Not Allowed" as answer.
On server side my PHP script handle such requests but it seems filtered by the server itself (that's makes the difference from the similar already answered question - Moreover other questions seems to refers to an old version of Apache).
Can I manage some configurations on .htaccess file or I have to modify the .conf files under /etc/apache2?
Thanks a lot.
Try the following changes on your server:
Open "/etc/httpd/conf/httpd.conf" and look for the following blocks:
<Limit GET POST OPTIONS PROPFIND>
Order allow,deny Allow from all
</Limit>
<LimitExcept GET POST OPTIONS PROPFIND>
Order deny,allow Deny from all
</LimitExcept>
Then just add PUT and DELETE after PROPFIND. Then Restart httpd by "/sbin/service httpd restart" or service httpd restart.
Note: In some servers , mostly the ones with a control panel (DA,cPanel,..) you may change this file :/etc/httpd/conf/extra/httpd-directories.conf
I hope it solves your problem.
For Debian/Ubuntu.
In your conf:
<Location "/">
AllowMethods GET PUT
</Location>
In console:
sudo a2enmod allowmethods
sudo systemctl restart apache2.service
You can use allowmethods_module to enable that.
It's been available since apache version 2.3 but still experimental though.
<Location "/path/to/directory">
AllowMethods PUT DELETE
</Location>
I got the same error and the root cause is the redirects to https (80-443) are not occurring which one of the things are causing the docker client to fail while allowing the browser to work. I added below directives in Apache httpd (apache2) and it worked for me.
<VirtualHost *:80>
RedirectPermanent / https://%{SERVER_NAME}/
RewriteEngine On
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
# General setup for the virtual host
ServerName example.org
ServerAdmin help#example.com
ErrorLog /tmp/error_log
SSLProxyEngine On
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
AllowEncodedSlashes NoDecode
ProxyPreserveHost On
ProxyPass / http://<BackendIP>/ connectiontimeout=10 timeout=3600
ProxyPassReverse / http://<BackendIP>/
</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.

Redirect a frontend URL to another backend webserver

I'm using a framework that uses a full-stack to display all its webpages. This runs standard on port 9000. Very fine, but when going into production, the server seems to block everything except a few standard ports.
So therefore, the framework (Play framework), advises you to do this in your front-end webserver (in my case Apache2).
file: play.conf
<VirtualHost *:80>
ServerName http://avon.ugent.be
CustomLog /var/www/log/proxy-access.log common
ErrorLog /var/www/log/proxy-error.log
ProxyPreserveHost On
DocumentRoot /var/www
<Location /dev/app>
AuthType Basic
AuthName "Test Omgeving"
AuthUserFile /var/trac/htpasswd
Require valid-user
ProxyPass http://127.0.0.1:9000/
ProxyPassReverse http://127.0.0.1:9000/
</Location>
</VirtualHost>
This of course requires the mod_proxy module, that is being enabled with a2enmod mod_proxy. (I run this on a Debian distro)
The idea is to run two webservers, one front-end and one back-end with the application.
The reloading of the apache webserver works fine, the site is enabled and everything, but when I surf to the http://my.website.com/dev/app url, it renders a 404... Suggestions what's going wrong?
EDIT3:
After 10+ hours of trying it boils down to this:
I found the debugging command (finally :p) and this is the output:
apache2ctl -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server avon.ugent.be (/etc/apache2/sites-enabled/000-default:1)
port 80 namevhost avon.ugent.be (/etc/apache2/sites-enabled/000-default:1)
port 80 namevhost avon.ugent.be (/etc/apache2/sites-enabled/play.conf:1)
Syntax OK
Which indicates that the virtual server is indeed being added to the configuration.
But still, it renders a 404. Now, somewhere i've read that's because there is no index.html in that path. Is that necessary if you just want to use a reverse proxy?
For a start please try using Location instead of Directory. Directory is used for identifying directory paths on the filesystem not paths relative to the document root.
<Location '/dev/app'>
AuthType Basic
AuthName "Test Omgeving"
AuthUserFile /var/trac/htpasswd
Require valid-user
</Location>
Try the following. It should prompt for the username/password and then pass the request to http://127.0.0.1:9000. In my case, Apache gives a "Service Temporarily Unvavailable", which you should get as well if you turn off the application running on port 9000
<VirtualHost *:80>
ServerName my.website.com
<Location /dev/app>
AuthType Basic
AuthName "Test Omgeving"
AuthUserFile passwd/.htpasswd
Require valid-user
ProxyPass http://127.0.0.1:9000
ProxyPassReverse http://127.0.0.1:9000
</Location>
</VirtualHost>
If you still get a 404, can you confirm that it's not the backend server sending it?