node.js - 在同一台服务器上运行 PHP 和 Node.js 的问题
问题描述
我正在尝试在同一台服务器上运行带有 socket.io 的 Node.js。我们有一个小工具可以让用户测试他们的 websockets,你可以在这里找到。现在的问题是它没有与域连接,例如如果不使用原始 ip https://123.23.23.12:3001/socket.io/?EIO=3&transport=polling&t=NIHXfZI(为了保密而披露真实 ip)它连接到 socket.io 但是当我使用https://www.101toolbox.com:3001/socket.io/?EIO=3&transport=polling&t=NIHXfZI它只是无法连接。现在我尝试创建反向代理和其他东西,但它也没有工作,服务器使用 laravel 和一些由 pm2 运行的节点 js,请注意它们在将网站移动到新主机之前工作没有使用任何特殊apache2 配置。这是apache2配置,我真的没有想法。
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName 101toolbox.com
ServerAlias www.101toolbox.com *.101toolbox.com 101toolbox.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/101toolbox/public
ErrorLog ${APACHE_LOG_DIR}/101toolbox_error.log
CustomLog ${APACHE_LOG_DIR}/101toolbox_access.log combined
<Directory /var/www/101toolbox>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
SSLCertificateFile /etc/letsencrypt/live/101toolbox.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/101toolbox.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
解决方案
这是使节点应用程序工作的 apache2 的正确配置。事实证明,我应该为 socket.io 注册 2 个不同的代理。
<IfModule mod_ssl.c>
<VirtualHost *:443>
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
ServerName 101toolbox.com
ServerAlias www.101toolbox.com *.101toolbox.com 101toolbox.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/101toolbox/public
ErrorLog ${APACHE_LOG_DIR}/101toolbox_error.log
CustomLog ${APACHE_LOG_DIR}/101toolbox_access.log combined
<Directory /var/www/101toolbox>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
SSLProxyEngine On
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
SSLProxyCheckPeerExpire off
ProxyRequests Off
ProxyPass /node https://127.0.0.1:3000
ProxyPassReverse /node https://127.0.0.1:3000
ProxyPass /sockets https://127.0.0.1:3001
ProxyPassReverse /sockets https://127.0.0.1:3001
ProxyPreserveHost On
ProxyPass /socket.io https://127.0.0.1:3001/socket.io
ProxyPassReverse /socket.io https://127.0.0.1:3001/socket.io
SSLCertificateFile /etc/letsencrypt/live/101toolbox.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/101toolbox.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
推荐阅读
- crystal-reports-2013 - Crystal Reports 2013 在每个组的开头禁止空白页
- php - 如何重定向保留 URL 参数的目录?
- java - 为什么我的项目中仍在下载和初始化 EhCache
- caching - 缓存、分支预测器和 TLB 维护操作
- sql - 如何计算 db2 中两个日期列之间的天数?如何更正此查询中的天数差异?
- java - 有没有办法使用 Selenium WebDriver 而不通知文档它是由 WebDriver 控制的?
- ruby - 使用哈希图测试订单
- c++ - 理解 char 变量计数的 C++ 问题
- javascript - 在 React 中使用常规函数未触发 onClick 操作
- sql - dml 的通用 sql 脚本