<script src="/socket.io/socket.io.js"></script>
<script>
$(function () {
var socket = io.connect('https://domain.ru:9081');
socket.emit('data', JSON.stringify({"user": "", "index":""}) );
});
</script>
<script src="/socket.io/socket.io.js"></script>
<script>
$(function () {
var socket = io.connect('https://domain.ru/connect/');
socket.emit('data', JSON.stringify({"user": "", "index":""}) );
});
</script>
var express = require('express'),
app = express(),
server = require('http').createServer(app),
io = require('socket.io')(server),
log4js = require('log4js');
var httpPort = 9081;
var qStatus = false;
log4js.configure({
// Error
appenders: { error: { type: 'file', filename: 'socket-error.log' } },
categories: { default: { appenders: ['error'], level: 'error' } },
// Trace
appenders: { info: { type: 'file', filename: 'socket-info.log' } },
categories: { default: { appenders: ['info'], level: 'trace' } },
});
const logger = log4js.getLogger('PATH: '+__filename);
const connects = [];
app.set('views', __dirname + '/views')
app.set('view engine', 'pug')
app.use(express.static(__dirname + '/public'))
server.listen(httpPort, function () {
logger.info('Server listening at port', httpPort);
});
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html');
});
io.attach(server);
io.on('connection', function(user) {
user.on('data', function(data){
...
});
user.on('disconnect', function () {
...
});
});
});
upstream backend_hosts {
server XXX.XXX.XX.XX:9081;
}
server {
server_name domain.ru;
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
listen 443 ssl;
root /var/www/TEST;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
index index.php index.html index.hml index.phtml;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
location / {
try_files $uri $uri/ /index.php?q=$uri & $args;
}
location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log off;
expires max;
}
location ~ /\.ht {
deny all;
}
location ~ \.php$ {
fastcgi_index index.php;
fastcgi_keep_conn on;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location /connect/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400;
proxy_pass http://backend_hosts;
}
}