Add websocket server and configs

This commit is contained in:
Felix Klenner 2024-07-19 19:18:16 +02:00
parent effe778067
commit bf442d3554
3 changed files with 135 additions and 0 deletions

View file

@ -34,6 +34,81 @@ geoip2 /var/lib/GeoIP/GeoLite2-ASN.mmdb {
} }
``` ```
Then the following should be used, to pass this data to php:
```
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
#for proxy detection
fastcgi_param HTTP_X_FORWARDED_FOR $http_x_forwarded_for;
#pass all geoip data
fastcgi_param GEOIP_CONTINENT_CODE $geoip2_data_continent_code;
fastcgi_param GEOIP_CONTINENT_NAME $geoip2_data_continent_name;
fastcgi_param GEOIP_COUNTRY_CODE $geoip2_data_country_code;
fastcgi_param GEOIP_COUNTRY_NAME $geoip2_data_country_name;
fastcgi_param GEOIP_SUBDIVISION $geoip2_data_subdivision;
fastcgi_param GEOIP_CITY_NAME $geoip2_data_city_name;
fastcgi_param GEOIP_POSTAL_CODE $geoip2_data_postal_code;
fastcgi_param GEOIP_LATITUDE $geoip2_data_location_lat;
fastcgi_param GEOIP_LONGITUDE $geoip2_data_location_long;
fastcgi_param GEOIP_ACCURACY $geoip2_data_location_acc;
fastcgi_param GEOIP_TIMEZONE $geoip2_data_location_time;
fastcgi_param GEOIP_ASN $geoip2_data_asn;
```
The following is the nginx config for the server block:
```
server
{
listen 80;
listen [::]:80;
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name v4.ip.zuim.de v6.ip.zuim.de ip.zuim.de 89.58.44.51 [2a03:4000:67:e03::1];
root PROJEKTORDNER
location /speedtest
{
proxy_pass http://unix:/run/nodejs/speedtest/socket;
proxy_http_version 1.1;
#include include/proxy_params;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
include include/php;
include include/ssl_zuim;
}
```
Download these files directly and add them in the main folder: Download these files directly and add them in the main folder:
- https://ip.zuim.de/0B.zip - https://ip.zuim.de/0B.zip
- https://ip.zuim.de/1MB.zip - https://ip.zuim.de/1MB.zip

52
node_server/main.js Normal file
View file

@ -0,0 +1,52 @@
var path = "/speedtest";
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http, {path: path
//, cors: {
// origin: [/zuim\.de$/, /craftandbuild\.de$/],
// methods: ["GET", "POST"]
// }
});
var fs = require('fs');
io.on('connection', function(socket)
{
socket.on('pingUp', function(msg)
{
socket.emit('pongDown', msg);
});
socket.on('downReq', function(msg)
{
if(new RegExp('[0-9]+').test(msg))
{
fs.readFile(__dirname + '/data/' + msg, function (err, data)
{
socket.emit('downDataStart', '');
socket.emit('downData', data);
});
}
});
socket.on('upTest', function(msg)
{
socket.emit('upOk', '');
});
socket.on('pingT', function(msg)
{
socket.emit('pongT', '');
});
});
//http.listen(3000, function(){
// console.log('listening on *:3000');
//});
var socket = '/var/run/nodejs'+path+"/socket";
if(fs.existsSync(socket))
fs.unlinkSync(socket);
http.listen(socket, function()
{
fs.chmodSync(socket, '666');
});

8
node_server/package.json Normal file
View file

@ -0,0 +1,8 @@
{
"name": "ipinfo_server",
"version": "0.0.1",
"dependencies": {
"express": "^4.13.4",
"socket.io": "^4.2.0"
}
}