Apache2 proxy to spring-boot app, problem with Oauth2 - facebook

I'm running the Tomcat on 8080 port. I have an apache2 proxy, it has SSL certificates, and it passes all encrypted traffic from 443 to 8080 port. All works fine, except facebook authentication.
If apache2 turned off, and SSL is on in tomcat - it is working. I believe the problem in traffic encryption, maybe the facebook retrieves the request from my not SSL tomcat server?
My apache config:
ServerName thing-tracker.ga
SSLEngine On
SSLCertificateFile /opt/cert/cert.pem
SSLCertificateKeyFile /opt/cert/privkey.pem
SSLCertificateChainFile /opt/cert/chain.pem
DefaultType text/html
ProxyRequests off
ProxyPreserveHost On
RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket
RewriteRule /(.*) ws://localhost:8080/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket
RewriteRule /(.*) http://localhost:8080/$1 [P,L]
# ProxyPass / http://localhost:8080/
# ProxyPassReverse / https://localhost/
The error:
Forwarding to error page from request [/login/oauth2/code/facebook] due to exception
[An error occurred reading the OAuth 2.0 Error: JSON parse error:
Cannot deserialize instance of java.lang.String out of START_OBJECT token;
nested exception is
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of java.lang.String out of START_OBJECT token
at [Source: (sun.net.www.protocol.http.HttpURLConnection$HttpInputStream); line: 1, column: 10] (through reference chain: java.util.LinkedHashMap["error"]);

Try to force https on apache:
RequestHeader set X-Forwarded-Proto https
And on your spring boot properties add:
server.use-forward-headers=true
server.tomcat.remote_ip_header=x-forwarded-for
server.tomcat.protocol_header=x-forwarded-proto
I was with the same problem, but this solved.

Related

Flutter Socket io Error on WebSocketException: Connection to was not upgraded to websocket

I use this package and it work properly on test websites but in app I got this Error
WebSocketException: Connection to 'https://socket.excopro.com:0/socket.io/?EIO=3&transport=websocket#' was not upgraded to websocket
and this is my Code
SocketService() {
var socket = io(
'https://socket.excopro.com:443/', <String, dynamic>{
'transports': ['websocket'],
'autoConnect': true,
});
socket.on('connect', (_) {
print('connect');
socket.emit('msg', 'test');
});
socket.on("connecting", (data) => print('connecting'));
socket.on('connect_error', (data) {
print(data);
socket.emit('msg', 'test');
});
}
I have met the same issue.
For my case, I use Nginx as proxy. I solve the issue by added some proxy header to my Nginx configuration.
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
You can refer to this link.
I ran into this error in my Flutter/Dart app which is being serviced by NGinx + NChan. It turned out that the wss:... url that I was creating in Dart was malformed - easily done if you are doing string interpolation in Dart, PHP and JS all within the space of a few minutes given that each language has its own way of interpreting interpolated variables in braces. The result was that location = ~ /path/(regex)$ setting in my Nginx/NChan conf was not recognizing the URL as one that required upgrading to wss. Nginx then proceeded to try and find the resource at https://example.com/malformed/path without upgrading it to wss which then threw up this error in Dart.
Lesson - when this happens check that the URL you are trying to reach is well formed so it ends up being recognized as one requring an upgrade to wssserver side.
You have make sure to enable websocket in Virtual Host.
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteCond %{HTTP:Connection} Upgrade [NC]
RewriteRule /(.*) ws://127.0.0.1:3055/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /(.*) http://127.0.0.1:3055/$1 [P,L]
Here is the complete Virtual Host if anyone needs,
<VirtualHost *:80>
ServerName domain.com
ServerAlias www.domain.com
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Require all granted
</Proxy>
ProxyPass / http://127.0.0.1:3055/
ProxyPassReverse / https://127.0.0.1:3055/
ProxyPass /api http://127.0.0.1:3055/api
ProxyPassReverse /api https://127.0.0.1:3055/api
RewriteEngine on
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteCond %{HTTP:Connection} Upgrade [NC]
RewriteRule /(.*) ws://127.0.0.1:3055/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /(.*) http://127.0.0.1:3055/$1 [P,L]
RewriteCond %{SERVER_NAME} =domain.com [OR]
RewriteCond %{SERVER_NAME} =www.domain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
Received this error when there was a mismatch on the client and server versions of socket_io. Try finding the matching version to the version the server is using.
I had for the same error, this is what my environment:
VPS with docker
Azuracast as container
Nginx proxy manager as container
a public domain that point to the Azuracast via hots in nginx proxy manager.
a flutter/dart mobile app that stream the radio flux, and I wanted to get "Now playing audio" updates via Websocket.
I had the same error when trying to connect via https schema with/without port.
I finally found that in nginx proxy manager I have to activate the Websocket option in the host I created. Then changed my url to wss://... instead of https://...
In flutter I used this package for websocket => web_socket_channel: ^2.2.0
and this is the line of code to init the websocket:
var websocket = IOWebSocketChannel.connect(Uri.parse('wss://xxx.com/api/live/nowplaying/my_station_shortcode'))

Apache Reverse Proxy produces too many redirects

I have configured apache to redirect HTTPS reqests to the local running application server PUMA. PUMA is part of the Ruby on Rails framework.
<IfModule mod_ssl.c>
<VirtualHost *:443>
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
Puma Server is listening on http://localhost:3000/
When I access this apache web site from a browser I get: Too many redirections.
And idea?
I had the same issue. Try to add after your Proxy:
RequestHeader set X-Forwarded-Proto https to your ...ssl.conf which is in sites-available folder.
I had same issue, I was trying to setup a SSL termination reverse proxy with apache. I followed this article.
Using 0.0.0.0 instead of localhost worked for me.
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName exemple.com
SSLCertificateFile /path/fullchain.pem
SSLCertificateKeyFile /path/privkey.pem
ProxyPass / http://0.0.0.0:80/
ProxyPassReverse / http://0.0.0.0:80/
</VirtualHost>
</IfModule>

apache rewrite is doing redirect

In apache2 rewrite is doing redirect when i am writing following rewrite rule
RewriteRule ^id/(.*)$ http://pickyourjersey.com/index.php?id=$1 [NC,L]
and if i am removing NC then it shows error
Bad Request
Your browser sent a request that this server could not understand.
Apache/2.4.7 (Ubuntu) Server at pickyourjersey.com Port 80
If i am using relative path it works fine
replace with
RewriteEngine on
RewriteRule "^id/(.*)" "http://pickyourjersey.com/index.php?id=$1" [NC,L]

Redirection from www.example.com to www.example.com/index.jsp

I have setup apache2 and tomcat7 on ubuntu 14.04.
my domain name is www.example.com , which I want to redirect to the www.example.com/index.jsp on to the tomcat as this is the login page. How can this be done? The set up works fine for a request made to www.example.com/index.jsp. The apache virtualHost setting is
ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
the redirection in my understanding should happen on the apache. As the apache is acting just as a proxy and not serving any requests by itself can we use the directive ? Where and how to make the change. Any pointers appreciated
I tried rewriting the url in the virtualHost but it doesn't seem to be working
ServerName www.example.com <br>
RewriteEngine On <br>
RewriteRule ^http://www\.example\.com$ https://www.example.com/index.jsp [R]
You can use the following rewrite rule
RewriteEngine On
RewriteRule ^/$ /index.jsp [R]
It basically will search that if, the uri path starts and ends with a / it will redirect it to /index.jsp , this should do the trick.

Debug /http-bind/ issue Openfire

Im using openfire for the xmpp to my website. I have done a server move and relocated the site on the same server as openfire as they were both on different servers before.
Since the move im getting error 500 on the /http-bind/ request on my website.
How can i debug this or what to i need to consider that may be causing the error 500 on /http-bind/
Error log
[warn] proxy: No protocol handler was valid for the URL /http-bind/. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.
Short answer: You need to load the 'proxy_http' module in Apache.
There are some instructions I wrote in the Prosody documentation on setting up BOSH with Apache, but they should apply equally to any BOSH/XMPP server. In particular I'm not sure whether Openfire is fussy about /http-bind vs. /http-bind/. Therefore if the below instructions do not work, try adding the / to the end of the URL.
Summary
Run: sudo a2enmod rewrite proxy proxy_http
Add the following lines to your Apache config:
<Location /http-bind>
Order allow,deny
Allow from all
</Location>
RewriteEngine On
RewriteRule ^/http-bind$ http://example.com:5280/http-bind [P,L]
I would like to add that with a properly configured server you can just put this in your .htaccess in the root of your web folder:
<IfModule mod_rewrite.c>
RewriteEngine On
# Rule1
RewriteCond %{REQUEST_URI} ^/chat1/http-bind
RewriteRule ^.*$ http://chatsrv1.joynmenow.com:7070/http-bind/ [P,L]
# Rule 2
RewriteCond %{REQUEST_URI} ^/chat2/http-bind
RewriteRule ^.*$ http://chatsrv2.joynmenow.com:7070/http-bind/ [P,L]
</IfModule>
I'm not exactly sure what configs are required to allow this in a .htaccess however my godaddy VPS allowed me to do this in it's default configuration.