Reverse proxy websocket IIS - iis

I would like to use IIS to proxy websocket on windows. So, I set up IIS 8 in Winserver 2012, for reverse proxying a websocket server app. But I don't know how to configure IIS. There is just redirect rules for HTTP and HTTPS, no WS. I would like to have the same thing as apache :
<Location /ws>
ProxyPass ws://127.0.0.1:8080
ProxyPassReverse ws://127.0.0.1:8080
</Location>
The request ws://127.0.0.1:80/ws will be redirect to ws://127.0.0.1:8080/ws.
Thank you.

Related

Apache 2.4 - Simple reverse proxy - not working for multiple entries

I referred the below link and configured the proxy.
https://httpd.apache.org/docs/2.4/howto/reverse_proxy.html
When I configure a proxy for a single application as below in Apache 2.4 in the httpd.conf file, the proxy configuration is working fine. I am able to access my application through the proxy server URL.
ProxyPass / http://host1:8888/
ProxyPassReverse / http://host1:8888/
However If I try configure for two application like below, I am not able to access any of the application.
ProxyPass /nifi http://host1:8888/
ProxyPassReverse /nifi http://host1:8888/
ProxyPass /kibana http://host2:5601/
ProxyPassReverse /kibana http://host2:5601/
Not knowing how you try to reach the application makes it difficult to guess what's might be wrong.
I suggest you to change the proxies config as following:
ProxyPass /nifi/ http://host1:8888/
ProxyPassReverse /nifi/ http://host1:8888/
ProxyPass /kibana/ http://host2:5601/
ProxyPassReverse /kibana/ http://host2:5601/
then try to reach the endpoint pointing your browser to http://youdomain/nifi/ and http://youdomain/kibana/ and check the logs for errors.

POST becomes GET after ProxyPass

I have a nodejs app running inside a docker container on port 3050. If I allow the port through the firewall then everything works fine. But if I try to ProxyPass it then the app seems to receive GET instead of POST.
ProxyPass / http://localhost:3050/
When I look at the access log apache receives the request as a POST. But logging the req.method in expressjs results in GET. I have also tried loads of other settings
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://localhost:3050/
ProxyPassReverse / http://localhost:3050/
RequestHeader set X-Forwarded-Proto "https"
RequestHeader set X-Forwarded-Port "443"
The strangest thing is that I am Proxying lots of other services like gitlab and keycloak without any problem.
Could it be something to do with HTTP 1.1 or HTTP 2? Or does my httpd server have some setting messed up?
I was only testing with postman...obviously in future I should try curl or something as well. Turns out that postman has a setting "Redirect with the original HTTP method instead of the default behavior of redirecting with GET." which is turned off by default. I don't know whether the browser will behave like this but at least now it seems to be working
update:
Actually it wasn't even that setting. it was because i had not prefixed the url with https:// due to a training course which excluded the protocol because we weren't working with secure. so the httpd server proxied port 80 to 443 and postman didn't handle it correct. as i would be hitting directly https in production it shouldn't be a problem

Proxy Error 502 on Apache2 for Reverse Proxy to NodeJs Subdomain App on Digital Ocean

Hello guys
Im trying to deploy my nodejs api on Digital Ocean, under subdomain https://api.host.com. Its has some path bellow, all starting by /v0.1.
For example https://api.host.com/v0.1/users
On this droplet the nodejs app is running over http://localhost:3000
At the same droplet i have got other app, a website hosted on Apache and responds at https://host.com it works fine.
Im using Apache for Reverse Proxy make all calls from https://api.host.com/ to http://localhost:3000.
Actually It works only for root path, i mean try to access https://api.host.com/ responds right but when i try to access other path i get error
Proxy Error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request
Reason: DNS lookup failure for: 127.0.0.1:3000v0.1
Apache/2.4.29 (Ubuntu) Server at api.host.com Port 443
HTTP Status Code: 502 Proxy Error
my vhost looks like...
<VirtualHost *:80>
...
...
ServerName api.host.com
ProxyPass /.well-unknown/ !
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Require all granted
</Proxy>
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
...
...
</VirtualHost>
Help please!
I am doing the same thing with an Apache server forwarding requests from a subdomain via a proxy to my nodeJS app listening on port 8080.
I believe that you only need to proxy pass the root to localhost:3000 and the nodeJS app is supposed to handle the routing.
For instance, if you are using express, something like.....
app.get('/v.01/users/', function (req, res) {
res.sendFile('/v.01/users/index.html'); });

Apache Reverse Proxy and localhost - "Mixed content, the content must be served over HTTPS"

I have created a reverse proxy for my node server that runs on localhost, so that it can be served over HTTPS.
The forwarding works grate, however when the app tries to make requests I get:
Mixed Content: The page at 'https://foo.com/' was loaded over HTTPS,
but requested an insecure XMLHttpRequest endpoint
'http://localhost:8888/graphql?query=%7Bnotifications(userid)%7Bid%2C…
This request has been blocked; the content must be served over HTTPS.
Vhost config:
<VirtualHost *:443>
ServerName www.foo.com
ServerAlias foo.com
DocumentRoot /var/www/foo/
ErrorLog /var/www/foo/error.log
CustomLog /var/www/foo/requests.log combined
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
SSLCertificateFile "/etc/letsencrypt/live/foo.com/cert.pem"
SSLCertificateKeyFile "/etc/letsencrypt/live/foo.com/privkey.pem"
ProxyPreserveHost On
ProxyRequests Off
ProxyPass / http://localhost:8888/
ProxyPassReverse / http://localhost:8888/
</VirtualHost>
What is missing from my setup?
You are openning the page on https://foo.com/, but URLs within your page contain hardcoded localhost domain and port. While rendering the page, client browser will try to fetch 'http://localhost:8888/graphql effectively skipping apache (which is running on port 80, on server foo.com) and hitting directly your node app, which will 1) work only if you run the browser from the very same machine where you have your node app running, and 2) even then, you will get the above error since some page assets are loaded using http.
When you use relative URLs (for example URL that begins with /), browser will prepend the base URL, resulting in https://foo.com/graphql.
Absolute vs relative URLs
You need to add a SSL certificate to your node.js app. Enabling it on apache won't help since the apache is forwarding the requests to your node.js app on port 8888 (which communicates on plain http and not https). That's why you get the mixed content error. The initial request is on https on apache then forwarded to http to node.js
Steps to configure node.js app with a SSL certificate (you can use a self-signed certificate or a commercial one).
First you have to use ssl-root-cas available via npm. The configure it as follows:
'use strict';
var https = require('https')
, cas
;
// This will add the well-known CAs
// to `https.globalAgent.options.ca`
require('ssl-root-cas').inject();
cas = https.globalAgent.options.ca;
cas.push(fs.readFileSync(path.join(__dirname, 'ssl', '01-ssl-intermediary-a.pem')));
cas.push(fs.readFileSync(path.join(__dirname, 'ssl', '02-ssl-intermediary-b.pem')));
cas.push(fs.readFileSync(path.join(__dirname, 'ssl', '03-ssl-site.pem')));
Try and see if that works!

Reverse proxy not working

I am trying to create a reverse proxy using Apache. I'm using Apache to serve a php application and I have written an API in node which uses Express.
Inside my PHP application I use AJAX calls to node to retrieve JSON. I want to use port 80 for the calls in the PHP app and a reverse proxy using Apache to Express.
The issue I have is that I get an error 500 (proxy request).
My suspicion is that it has something to do with SSL.
Here's part of the configuration I have for Apache:
SSLEngine On
ProxyPreserveHost On
SSLProxyEngine On
ProxyPass /stats https://127.0.0.1:8081/
ProxyPassReverse /stats https://127.0.0.1:8081/
ProxyRequests on
Here's how I configured node:
app.listen(8081, function () {
console.log('Listening on port 8081!')
})
I got the proxy to work correctly. The issue was that in ProxyPass and ProxyPassReverse were set to https when https was not enabled.

Resources