apache proxy HTTPS to HTTP with POST data - linux

I have mobile a app uploading to https://mydomain.com/files/incoming_files.php and https://mydomain.com/api/v2/incoming_files.php
Ubuntu 11.04, Apache/2.2.17
Some of the uploads times out in the SSL handshake.
Therefore I'm trying to proxy POST upload requests to the PHP upload scripts from https:// to http:// and keep the POST data.
Throws these errors:
(70007)The timeout specified has expired: proxy: prefetch request body failed to 1.2.3.4:80
(103)Software caused connection abort: proxy: pass request body failed to 1.2.3.4:80
proxy: pass request body failed to 1.2.3.4:80
This is my config:
<VirtualHost 1.2.3.4:443>
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule ^/?files/incoming_files\.php http://%{SERVER_NAME}/files/incoming_files\.php [NC,P]
RewriteRule ^/?api/v2/incoming_files\.php http://%{SERVER_NAME}/api/v2/incoming_files\.php [NC,P]
SSLProxyEngine on
ProxyRequests Off
ProxyPreserveHost On
SetEnv proxy-sendchunked 1
SetEnv proxy-sendcl 0
ProxyPass /files/incoming_files.php http://mydomain.com/files/incoming_files.php
ProxyPassReverse /files/incoming_files.php http://mydomain.com/files/incoming_files.php
ProxyPass /api/v2/incoming_files.php http://mydomain.com/api/v2/incoming_files.php
ProxyPassReverse /api/v2/incoming_files.php http://mydomain.com/api/v2/incoming_files.php
Have tried to: Set Rewrite without ProxyPass. Set ProxyPass without Rewrite. Set with/without SetEnv proxy-sendchunked 1/proxysend-cl 0
Any idea what the best solution is, and what I'm doing wrong?

I'm seeing the same error messages in my apache access log:
[error] (103)Software caused connection abort: proxy: pass request body failed to X.X.X.X:Y (hostname)
[error] proxy: pass request body failed to X.X.X.X:Y (hostname) from Z.Z.Z.Z ()
with the only difference seeming to be that I'm running a tcServer (Tomcat) backend.
What I can tell you is that I'm also seeing a 502 response code associated with the upload request.
"POST /<path_to_target>/upload.do?_t=1407181458532 HTTP/1.1" 502 305
I think you might be on to something with the fact that your ProxyPass is redirecting HTTPS to HTTP and that is something I need to test.
One thing I would suggest is that you change update the ProxyRequests value to On.
ProxyRequests On

Related

Apache reverse proxy not loading resources

I've configured proxy reverse with apache 2.4 on a server (ip for example 192.168.1.10) as follows:
ProxyRequests Off
ProxyVia Off
ProxyPreserveHost Off
ProxyPass "/foo/" "http://172.20.0.3/"
ProxyPassReverse "/foo/" "http://172.20.0.3/"
mod_proxy_html is loaded.
Where 172.20.0.3 is a docker container, hosted by the server.
When I browse to 192.168.1.10/foo/ I see on the url bar 192.168.1.10/index.php (index.php is the page I actually would like to browse), but the resources required to load index.php are not found. So I get 404 page not found.
Setting / instead of /foo works, but I need to configure other proxy on the same server too.
This Q/A does not provide solution for my case: Apache ProxyPass not loading Resources
What I'm missing? Thank you

NodeJS + Apache Proxy, having trouble with routing a secured websocket through (apache config help please)

I've looked through countless of posts on here on how to do this, and I wasn't able to get this simple task working. I'm using Apache as a proxy that is suppose to encrypt/decrypt TSL packets, and then have an unsecured communication with the NodeJS server. The problem is that the web application loads fine, however the websocket fails with an error 404 (not found) and I've had an error 200 before (handshaking issue). I've tried many different configurations and it's not working.
This is what I have on the client side.
const connection = new WebSocket('wss://example.com/wss');
Using wss:// instead of ws:// here because I want to have a secured connection.
On the server side, I have just the standard
ws.on('connection', w => {
w.on('message', msg => {
var data = JSON.parse(msg);
// do something with the message ...
});
});
This is my Apache config file
ServerName www.example.com RewriteEngine on
RewriteCond %{HTTP:Upgrade}=websocket [NC]
RewriteRule /(.*) wss://127.0.0.1:3000/$1 [P,L]
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
SSLProxyEngine on
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
ProxyPass /wss ws://127.0.0.1:3000/
ProxyPassReverse /wss ws://127.0.0.1:3000/
On the Apache side I'm not certain if I should have wss:// or ws:// for ProxyPass since it should be insecure between Apache and NodeJS. I put it as ws:// here but both ways didn't work. For this configuration I get 404 error.
Any help would be greatly appreciated! Thanks
I solved this problem with the Nginx reverse proxy,
The problem is the fact that I set up socket connection to be on the port 8080, but the proxy is set up for the port 3000. The issue should resolve if you put them on the same port.
i.e.
App server,
const ws = new WebSocket.Server({port: 3001});
Apache
ProxyPass /wss ws://127.0.0.1:3001/
ProxyPassReverse /wss ws://127.0.0.1:3001/

Express redirect wrong url

When use express res function redirect(url), i'm redirected to the wrong url !
My website URL is mywebsite.com :
function myroute(app) {
app.get(/route, function(req, res) {
var url = getMyUrl();
console.log(url); // https://otherwebsite.com/foo?bar=baz [OK]
res.redirect(url); // redirect to https://mywebsite.com/foo?bar=baz [WRONG!]
});
}
I don't know why express redirect to mywebsite.com with good parameters instead of otherwebsite.com
No idea why...
This bug occurs on production. On my develop environment the redirect URL is the good url.
Thanks in advance
EDIT
I also tried with:
res.location(url);
and
res.setHeader(302, {Location: url});
But it always redirect to the wrong URL...
My url variable is good but I receive this header response:
HTTP/1.1 302 Found
X-Powered-By: Express
Location: https://mywebsite.com/foo?bar=baz
Vary: Accept\r\nContent-Type: text/html; charset=UTF-8
Content-Length: 170
Date: Fri, 13 Jul 2018 21:52:18 GMT
Connection: keep-alive
EDIT 2
Ok more tests here :
res.redirect("https://www.google.fr/toto?key=value"); // https://mywebsite.com/toto?key=value **[fail]**
res.redirect("https://www.google.fr/toto"); // https://mywebsite.com/toto **[fail]**
res.redirect("https://www.google.fr"); // https://www.google.fr **[success]**
It seems to not redirect to the domain I want if I add a path. Any idea ?
EDIT 3
Maybe it's caused by my vhost ?
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName mywebsite.com
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5001/
<Location />
ProxyPassReverse /
Order deny,allow
Allow from all
</Location>
SSLCertificateFile ...
SSLCertificateKeyFile ...
</VirtualHost>
</IfModule>
Providing an actual answer this time, as my previous one was (rightfully so) deleted.
The incorrect URL redirections are definitely caused by:
ProxyPassReverse /
As this is what such directive does:
"lets Apache httpd adjust the URL in the Location, Content-Location and URI headers on HTTP redirect responses."
In my case, removing this directive was causing other internal redirection issues in my application, so I was trying to find out a way to add exceptions to it.
However, it turns out I never needed ProxyPassReverse (only ProxyPass) if I adjust the 'mountpath' of my Express node js configuration to match the path of the proxy server. Not sure if this answer will help you as an actual solution, but it managed to solve it on my node application using Apache as reverse proxy.
I believe 301 needs to be included.
Try changing res.redirect(url) to res.status(301).redirect(url) and see if it fixes the issue.

Ubuntu - Apache - Reverse Proxy - NodeJS 302 : moved permanently on post method

I have an application running on my VPS at http://localhost:3000.
I'm trying to make a reverse Proxy with Apache2 to make it accessible at node.mydomain.net.
With that virtualhost config :
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
ServerName node.mydomain.net
ServerAlias www.node.mydomain.net
</VirtualHost>
It's actually working with the welcome page, but when i'm trying to connect, the POST method to node.mydomain.net/authenticate, it's actually return in the web inspector :
request method : POST Status Code : 302 Moved Temporarily.
Im' not sure about the real problem and I found no solution by the moment. Can it a rewriting problem ? or a POST method not allowed problem ?
If anyone can send me on a serious trail, i'll be very happy.
Many thanks.

CSS not loading when site is accessed over HTTPS using an Apache reverse proxy server

Thanks in advance for any help!
I'm running Ubuntu 13.1 on an EC2 instance. My app is written in Node.JS (based off NodeBB) and I'm using Apache 2 as a reverse proxy server to establish a secure connection on port 443.
The problem is that when I visit the website via HTTPS, none of the CSS is rendered!
My browser registers a number of errors of these 3 types:
Failed to load resource: the server responded with a status of 502 (Proxy Error)
Uncaught ReferenceError: require is not defined
Failed to load resource: net::ERR_CONNECTION_TIMED_OUT
Here's my config file:
<VirtualHost *:443>
ServerName forum.ligma.com
SSLEngine on
SSLCertificateFile /etc/apache2/forum_ligma_com.crt
SSLCertificateKeyFile /home/ubuntu/.ssh/myserver.key
SSLCACertificateFile /etc/apache2/combined-ca.crt
<IfModule mod_proxy.c>
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
</IfModule>
ProxyPass / http://127.0.0.1:4568
ProxyPassReverse / http://127.0.0.1:4568
</VirtualHost>
Any ideas what's going wrong? Thanks!

Resources