[英]Config apache and nodejs socket.io
嗨,我正在使用apache 2.2和feathersjs的网站上工作。 在此网站上,我们拥有DV SSL,因此我们无法使用https访问子域。
我的节点应用程序正在3030端口上运行。 因此我可以使用以下地址访问feathersjs应用程序:
但https://mywebsite.com:3030无法正常工作。
我需要使用一个类似于https://mywebsite.com/socket/的位置来连接到feathersjs websocket(猜测ws:// localhost:3030)
这是客户端代码:
const host = 'https://mywebsite.com/socket';
const socket = io(host,{
transports: ['websocket'],
forceNew: true
});
我需要httpd配置才能通过https连接ws。
post_virtualhost_global.conf
<VirtualHost 185.173.106.42:80>
ServerName mywebsite.com
RewriteEngine on
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
RewriteRule .* ws://localhost:3030%{REQUEST_URI} [P]
ProxyPass /socket http://localhost:3030/
ProxyPassReverse /socket http://localhost:3030/
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
</VirtualHost>
<VirtualHost 185.173.106.42:443>
ServerName freevery.com
RewriteEngine on
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
RewriteRule .* ws://localhost:3030%{REQUEST_URI} [P]
ProxyPass /socket http://localhost:3030/
ProxyPassReverse /socket http://localhost:3030/
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location /feathers>
ProxyPass http://localhost:3030/
ProxyPassReverse http://localhost:3030/
</Location>
</VirtualHost>
如果我尝试使用http://mywebsite.com/socket连接网络套接字,则会显示
无法加载http://mywebsite.com/socket.io/?EIO=3&transport=polling&t=L-1lgZ1 :从' http://mywebsite.com/socket.io/?EIO=3&transport=polling&t=L-重定向1lgZ1 '到' https://mywebsie.com/socket.io/?EIO=3&transport=polling&t=L-1lgZ1 '已被CORS策略阻止:所请求的标题上没有'Access-Control-Allow-Origin'标头资源。 因此,不允许访问源' http:// localhost:3001 '。
如果我尝试使用https://mywebsite.com/socket连接网络套接字,则会显示
无法加载https://mywebsite.com/socket.io/?EIO=3&transport=polling&t=L-1lUP5 :所请求的资源上没有“ Access-Control-Allow-Origin”标头。 因此,不允许访问源' http:// localhost:3001 '。 响应的HTTP状态码为404。
我在.htaccess文件中添加了Header set Access-Control-Allow-Origin "*"
,但是存在问题。
我的配置有什么问题?
问题解决了。 Apache与nginx发生冲突,因此出现301错误。 因此,我使用nginx代理websocket,它可以在子域上正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.