I have made a good preparation: Apache 2.4 + PHP7 + WebSocket
Visit this link to see my preparation
details: Cannot load modules/mod_proxy_wstunnel.so into server
But when I run a simple WebSocket demo, I am meet with some problems. I have no idea how to solve them.
Websocket is a new concept to me. I have learned that Apache 2.4 supports WebSockets with mod_proxy_wstunnel.so.
My steps:
Edit httpd.conf, load mod_proxy and mod_proxy_wstunnel (of course both are in apachedir/modules)
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
Add proxy (still in httpd)
ProxyPass /ws ws://10.180.0.123/
ProxyPassReverse /ws ws://10.180.0.123/
create HTML client and PHP server (cd apachedir/htdocs)
client.html
<html>
<script>
var socket = new WebSocket("ws://10.180.0.123/server.php");
socket.onopen = function(e){
console.log("open success");
}
socket.onmessage = function(e){
console.log("mes:"+e);
}
//socket.close();
socket.send("Hello World");
</script>
<html>
server.php
<?php
echo "hello";
?>
4.start apache
/usr/local/apache2/bin/apachectl start
My questions:
When I open: 10.180.0.123/client.html, I got the following error:
Uncaught InvalidStateError: Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.
WebSocket connection to 'ws://10.180.0.123/server.php' failed: Error during WebSocket handshake: Unexpected response code: 200
I guess I should write some code in server.php, and run it. Am I right? And what should I write. I didn't find any information on google.
When I open: 10.180.0.123/ws/client.html, I get the following Apache error logs
[Wed Sep 28 00:14:54.063989 2016] [proxy:warn] [pid 6646:tid 140326217934592] [client 10.230.0.93:57508] AH01144: No protocol handler was valid for the URL /ws/client.html. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.
It seems the proxy module was not be loaded, but see my screenshot:
A PHP script returning "hello" is not a WebSocket server.
You need to run an actual WebSocket server and point your proxy configuration to it.
Look into Ratchet for a PHP based WebSocket server.
When you have the WebSocket server running, you need to setup your Apache config.
Assuming it runs on the same machine and on port 8080:
ProxyPass /ws ws://localhost:8080/
ProxyPassReverse /ws ws://localhost:8080/
And inside your client.html, you should connect your WebSocket to ws://10.180.0.123/ws.
Related
I have created a simple HTML page to control the movement of a simulated Gazebo Turtlebot using roslaunch rosbridge_server rosbridge_websocket.launch following this tutorial.
However, in the Web Console of the HTML page (F12) it shows the error "Firefox cant establish a connection to the server at ws://localhost:9090/." I am using the default rosbridge for the websocket(9090). In the Terminal I am also receiving the errors:
[-] failing WebSocket opening handshake ('WebSocket connection denied: origin 'null' not allowed')
[-] dropping connection to peer tcp4:127.0.0.1:41290 with abort=False: WebSocket connection denied: origin 'null' not allowed.
Does anyone have any suggestions on how I can fix this?
Given that you have followed the ROS tutorial and have created an HTML file as shown in Ros Bridge tutorial then you have to run:
runcore
rosrun rospy_tutorials add_two_ints_server
roslaunch rosbridge_server rosbridge_websocket.launch
Now that you have these up and running, you need to serve the html/javascript file (e.g. simple.html) and start the services etc. For example, you can serve the simple.html by using a SimpleHTTPServer, see below an example (e.g. simplehttpserver_test.py):
#!/usr/bin/env python
import SimpleHTTPServer
import SocketServer
class MyRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
if self.path == '/':
self.path = '/simple.html'
return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
Handler = MyRequestHandler
server = SocketServer.TCPServer(('127.0.0.1', 9089), Handler)
server.serve_forever()
Once you run the simplehttpserver_test.py you can open the browser on 127.0.0.1:9089 and you should be able to have it working.
Note that SimpleHTTPServer serves files from the current directory and below, directly mapping the directory structure to HTTP requests, which means that the simple.html should be in the same (or below) directory as the simplehttpserver_test.py. Last, the port for the simplehttpserver_test.py should differ from the one used for the Rosbridge WebSocket server (e.g. default is 9090).
I have upgraded a SonarQube server from 6.0 to 6.7.2. Everything is fine, except that, after logging in as user "admin" and navigating to tab Administration, clicking on subtab System yields an error message
An error has occurred: please contact your administrator.
In file web.log:
2018.03.06 11:38:24 ERROR web[AWH6436/ICo3FeIjAAAz][o.s.s.w.WebServiceEngine] Fail to process request http://<HOST NAME>:20295/sonarqube/api/system/info
java.lang.IllegalStateException: Failed to call HTTP server of process [key='ce', ipcIndex=3, logFilenamePrefix=ce]
at org.sonar.ce.http.CeHttpClientImpl.call(CeHttpClientImpl.java:171)
at org.sonar.ce.http.CeHttpClientImpl.retrieveSystemInfo(CeHttpClientImpl.java:60)
at org.sonar.server.platform.ws.StandaloneSystemInfoWriter.write(StandaloneSystemInfoWriter.java:53)
at org.sonar.server.platform.ws.InfoAction.handle(InfoAction.java:64)
at org.sonar.server.ws.WebServiceEngine.execute(WebServiceEngine.java:103)
at org.sonar.server.ws.WebServiceFilter.doFilter(WebServiceFilter.java:86)
at org.sonar.server.platform.web.MasterServletFilter$GodFilterChain.doFilter(MasterServletFilter.java:126)
...
Caused by: java.io.IOException: Server returned HTTP response code: 503 for URL: http://10.145.61.55
The IP address is that of the server. There is no mention of any port in the error message, I don't know if this has any relation with the error.
It seems that the Web component cannot access the Compute Engine component. However nothing particular was found in file ce.log which ends with a trace Compute Engine is operational.
I followed the short migration guide in https://docs.sonarqube.org/display/SONAR/Upgrading.
Environment: Linux, JDK 8, Oracle DB
Does anyone as a clue? Many thanks in advance.
For whoever who might stumble on the same issue: it was an error in my proxy configuration. Increasing the logging level by setting sonar.log.level=DEBUG in file sonar.properties yielded the following new traces in file web.log:
2018.03.07 11:52:04 DEBUG web[AWIAFTpArQRjrTzMAAAg][s.n.w.p.h.HttpURLConnection] sun.net.www.MessageHeader#668ee27b5 pairs: {GET http://127.0.0.1:40413/systemInfo HTTP/1.1: null}{User-Agent: SonarQube 6.7.2.37468 # AWHmcYEU8aGLjZ5sPfjj Java/1.8.0_60}{Host: 127.0.0.1:40413}{Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2}{Proxy-Connection: keep-alive}
2018.03.07 11:52:04 DEBUG web[AWIAFTpArQRjrTzMAAAg][s.n.w.p.h.HttpURLConnection] sun.net.www.MessageHeader#527214044 pairs: {null: HTTP/1.1 301 Moved Permanently}{Server: BlueCoat-Security-Appliance}{Location: http://10.145.61.55}{Connection: Close}
2018.03.07 11:52:04 DEBUG web[AWIAFTpArQRjrTzMAAAg][s.n.w.p.h.HttpURLConnection] Redirected from http://127.0.0.1:40413/systemInfo to http://10.145.61.55
2018.03.07 11:52:04 ERROR web[AWIAFTpArQRjrTzMAAAg][o.s.s.w.WebServiceEngine] Fail to process request http://<HOST NAME>:20295/sonarqube/api/system/info
The proxy was redirecting the Compute engine URL http://127.0.0.1:40413/systemInfo to http://10.145.61.55.
The solution was to add 127.0.0.1 to http.nonProxyHosts in file sonar.properties.
Have written simple server using fastcgi++ 2.1 lib and configured fastscgi in apache2 web server. When I make post request to the server with Content Type: application/json, server throws an internal server error. Have checked apache error.log file and found following log:
[Wed Jan 08 13:56:40 2014] [error] [client 127.0.0.1] FastCGI: server "/var/www/testserver" stderr: "Client sent unknown content type." from "http://abcd.com/testserver" with a POST request method.
When I set Content Type to "application/x-www-form-urlencoded" its working fine and request get served. Please help me on how to serve request with Content Type as "application/json". Is there any configuration required for this to support?
Yeah solved !
In fastcgi++ lib, Content Type "application/x-www-form-urlencoded" is hard-coded. Have changed it to "application/json" and rebuild the fastcgi++ lib. Now I'm able to serve request with Content Type "application/json".
So I have looked at many places to try and find the answer to this but could really use some other ideas for possibly how to fix this. I have gone into the new XAMPP security concept and change the Deny to Allow
#
# New XAMPP security concept
#
<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server- status|server-info))">
Order deny,allow
Allow from all
Allow from ::1 127.0.0.0/8 \
fc00::/7 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 \
fe80::/10 169.254.0.0/16
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</LocationMatch>
Above is what my httpd-xampp.conf looks like at the bottom. I still am getting the 403 error on the website when I go to the localhost. So I then looked to the error log and found I am getting this error.
[Fri Oct 26 08:58:29.731458 2012] [core:error] [pid 5096:tid 1680] (20024)The given path is misformatted or contained invalid characters: [client ::1:59590] AH00127: Cannot map GET /system/%3C?echo($template. HTTP/1.1 to file
I have no idea what this means but I am running out of options. If anyone could help me or has an idea as to what might be giving me this error. I will try anything.
Thanks in advance
Alright so it turns out the problem is with XAMPP. Not sure why but when I tested this on another dev server everything worked just fine. I am guessing it has something to do with the new XAMPP Security Concept. My best answer to this would be to change the Deny to Allow in that section of your httpd-xampp.conf file. This solution worked for many people except me.
This is mostly due to Apache bug 41441. The Apache coders don't call it a bug and have closed it as WONTFIX in end of 2009. However, I am also experiencing this error on heidisql.com where I get tons of misformatted requests from spammers, harvesters and other broken clients. My error log is full of these, and I would be glad to have a way to handle such requests with a redirect or rewriterule.
Your URL does not contain a colon (:)
/system/%3C?echo($template.
... but %3C translates to "<", which is also used in Windows filesystem paths, which is why Apache is blocking that request for security reasons.
I want to create a http2 server using node-http2 module without TLS. My code is as follows:
http2 = require('http2');
const bunyan = require('bunyan');
var log = bunyan.createLogger({name: "HTTP2 server without TLS!"});
var options = {
log: log
}
var server = http2.raw.createServer(options, function(request, response) {
console.log("Receiving HTTP2 request!");
// response.writeHead(200);
response.end('Hello world from HTTP2!');
});
server.listen(8000);
However, it does not work. When connecting to this server from chrome, it shows downloading something. When I closed the server, the downloading is finished with blank file (26 bytes).
Does anyone know what is wrong here? Do I need to configure the browser? Thanks in advance!
Chrome and all other browsers only support HTTP/2 over TLS (h2) and not plain HTTP/2 (h2c). So your browser does not understand what is returned from the server and apparently node-http2 does not send a proper error response when it receives a non-http2 request.
The problem seems not just from the browser. Using [curl] curllink that supports http2 over an http:// URL does not working either. Following is the output from the curl:
$ curl -I --http2 http://54.208.83.136:8000/ -v -k
* Trying 54.208.83.136...
* Connected to 54.208.83.136 (54.208.83.136) port 8000 (#0)
> HEAD / HTTP/1.1
> Host: 54.208.83.136:8000
> User-Agent: curl/7.47.1
> Accept: */*
> Connection: Upgrade, HTTP2-Settings
> Upgrade: h2c
> HTTP2-Settings: AAMAAABkAAQAAP__
>
As we see from the curl output. It sends http/1.1 Upgrade request with proper headers set as it supposed to do according to the [http2 rfc] rfclink.
On the server side, the logs were very long, so I present here only the content of msg in the relevant three logs.
New incoming HTTP/2 connection
Client connection header prelude does not match
PROTOCOL ERROR, Fatal error, closing connection
So basically the server closed the connection because the client connection header prelude does not match. By checking the code, I figured out the error was originated from the readPrelude function of [endpoint.js] endpointlink. It is a function to read the client header, but I don't know what is wrong in the client header :(.
Thus maybe I can say the node-http2 module does not support http2 over plaintext.
Update: it turns out that I was wrong. The node-http2 module do support http2 over plaintext with direct connecting, it does not support HTTP/2 server with Upgrade from HTTP/1.1. The problem resulted from the client side using Upgrade mechanism to connect to the server not supporting Upgrade. Using nghttp client to connect sever with prior knowledge works as follows.
$ nghttp http://127.0.0.1:8000/
Hello world from HTTP2!
nghttpd server also supports HTTP2 without TLS, even though it does not support HTTP Upgrade.
$ nghttpd -d /Documents/Proxy 8080 --no-tls -v
So I highly suggest to use nghttp when you want to test HTTP2 without TLS.