如果我已通过VPN连接到我的公司网络,则SSL外部网站(https://mysite.company.com)与node / socket.io一起工作
一旦我注销VPN并访问该网站,它就会在浏览器控制台中显示以下错误:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote
resource at https://mysite.company.com:8080/socket.io/?EIO=3&transport=polling&
t=1415132537790-0. This can be fixed by moving the resource to the same domain or enabling CORS.
我不知道为什么这只会在我离开VPN时发生...除了mysite.company.com之外没有任何请求......我已经尝试了很多不同的方法来解决这个问题错误......什么都没有用,我真的希望能得到一些支持......拜托!
我在.htaccess文件中有这个:
Header always set Access-Control-Allow-Origin "*"
Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
Header always set Access-Control-Max-Age "1000"
Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token"
Options FollowSymLinks
# Added a rewrite to respond with a 200 SUCCESS on every OPTIONS request.
RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L]
我的client.php(html部分)文件:
<script src="/js/socket.io-1.1.0.js"></script>
<script type="text/javascript">
var socket = io.connect('https://mysite.company.com:8080');
socket.on('notification', function(data) {
alert(data.message);
});
</script>
我的nodeServer.js:
var connectionsArray = [];
//var app = require('express')();
var https = require('https');
var fs = require('fs');
var options = {
key: fs.readFileSync('C:/certs/mysite_company_com.key'),
cert: fs.readFileSync('C:/certs/star_company_com.crt'),
ca: fs.readFileSync('C:/certs/DigiCertCA.crt'),
requestCert: true,
rejectUnauthorized: false
};
var server = https.createServer(options);
var io = require('socket.io').listen(server);
server.listen(8080, 'mysite.company.com');
io.set('origins', '*:*');