使用 apache 虚拟主机和 ssl 设置 Centrifugo 服务器
Setup Centrifugo server with apache virtual host and ssl
我知道大多数人都是倒着做的(apache 到 nginx),但是托管这个项目的服务器有其他具有特定配置的项目,所以...最好坚持我们现有的
我想要完成的是将用于 centrifugo golang 消息传递服务器的 nginx 虚拟主机配置从文档迁移到 apache2.4 example
这就是我的
#### This part it's commented because the server says it has incorrect syntax
# <Proxy "balancer://centrifugocluster"> {
# Enumerate all upstream servers here, in case you want to clusterize
# BalancerMember http://127.0.0.1:8000 # default host and port, change it if need it
# BalancerMember http://127.0.0.1:8001;
# </Proxy>
# ProxyPass / balancer://centrifugocluster/
<VirtualHost *:80>
ServerName centrifugo.MY_HOSTING.com
Redirect permanent ^(.*) https://centrifugo.MY_HOSTING.com/
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName centrifugo.MY_HOSTING.com
SSLEngine On
SSLCertificateFile /PATH/TO/CRT/FILE.crt
SSLCertificateKeyFile /PATH/TO/KEY/FILE.key
SSLCertificateChainFile /PATH/TO/CHAIN/FILE.crt
<Location "/connection/">
# Required for websockets
RewriteEngine on
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule /connection/(.*) http://127.0.0.1:8000/connection/ [P,L]
</Location>
<Location "/">
ProxyPass http://127.0.0.1:8000/
ProxyPassReverse http://127.0.0.1:8000/
</Location>
ErrorLog ${APACHE_LOG_DIR}/PATH/SERVER_LOG/FILE.log
CustomLog ${APACHE_LOG_DIR}/PATH/ACCESS_LOG/FILE.log combined
#### This part I'm not sure how to translate it
ErrorDocument 500 "Server Error 500"
ErrorDocument 502 "Server Error 502"
ErrorDocument 503 "Server Error 503"
ErrorDocument 504 "Server Error 504"
</VirtualHost>
</IfModule>
服务器有apache2.4和ubuntu18,centrifugo配置为
{
"secret": "SECRET",
"admin_password": "PASSWORD",
"admin_secret": "ADMIN-SECRET",
"api_key": "API-KEY",
"engine": "memory",
"admin": true,
"debug": true,
"log_level": "debug"
}
当前行为
- url 它已成功重定向到 https,其他项目可以很好地使用 ssl 配置
- 所有目录路径均已检查并正确无误
- 但是它说
404 page not found
- 当我在浏览器上尝试时
centrifugo.MY-HOST.com
确实显示了这个 404 错误
- 当我尝试使用
websocat
库(从服务器外部)时 websocat ws://centrifugo.MY-HOST.com/connection/websocket
它说 WebSocketError: Received unexpected status code. Error running
- 当我尝试使用
websocat
库时(从服务器内部,我的意思是通过 ssh 连接)websocat ws://localhost:8000/connection/websocket
它挂起...(我相信正在等待消息)
- centrifugo 服务器启动并侦听端口 8000,用 netstat 检查并主管说
running
- 我在 centrifugo 配置和虚拟主机中将
127.0.0.1
更改为 localhost
,将 documentRoot 添加到 apache 项目的路径中,但什么都没有...
我做错了什么?
算了,是我配置supervisor的错误。我有这个:
[program:centrifugo]
command=sudo /var/www/centrifugo-server/centrifugo
autostart=true
autorestart=true
stderr_logfile=/var/log/centrifugo.error.log
stdout_logfile=/var/log/centrifugo.output.log
我放置了带有完整路径的配置文件并删除了 sudo,效果非常好
command=/var/www/centrifugo-server/centrifugo --config=/var/www/centrifugo/config.json
我把它留在这里,以防对任何人有帮助
无论如何,如果有人知道如何翻译虚拟主机上的平衡器配置,那部分仍然缺失,谢谢
我知道大多数人都是倒着做的(apache 到 nginx),但是托管这个项目的服务器有其他具有特定配置的项目,所以...最好坚持我们现有的
我想要完成的是将用于 centrifugo golang 消息传递服务器的 nginx 虚拟主机配置从文档迁移到 apache2.4 example
这就是我的
#### This part it's commented because the server says it has incorrect syntax
# <Proxy "balancer://centrifugocluster"> {
# Enumerate all upstream servers here, in case you want to clusterize
# BalancerMember http://127.0.0.1:8000 # default host and port, change it if need it
# BalancerMember http://127.0.0.1:8001;
# </Proxy>
# ProxyPass / balancer://centrifugocluster/
<VirtualHost *:80>
ServerName centrifugo.MY_HOSTING.com
Redirect permanent ^(.*) https://centrifugo.MY_HOSTING.com/
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName centrifugo.MY_HOSTING.com
SSLEngine On
SSLCertificateFile /PATH/TO/CRT/FILE.crt
SSLCertificateKeyFile /PATH/TO/KEY/FILE.key
SSLCertificateChainFile /PATH/TO/CHAIN/FILE.crt
<Location "/connection/">
# Required for websockets
RewriteEngine on
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule /connection/(.*) http://127.0.0.1:8000/connection/ [P,L]
</Location>
<Location "/">
ProxyPass http://127.0.0.1:8000/
ProxyPassReverse http://127.0.0.1:8000/
</Location>
ErrorLog ${APACHE_LOG_DIR}/PATH/SERVER_LOG/FILE.log
CustomLog ${APACHE_LOG_DIR}/PATH/ACCESS_LOG/FILE.log combined
#### This part I'm not sure how to translate it
ErrorDocument 500 "Server Error 500"
ErrorDocument 502 "Server Error 502"
ErrorDocument 503 "Server Error 503"
ErrorDocument 504 "Server Error 504"
</VirtualHost>
</IfModule>
服务器有apache2.4和ubuntu18,centrifugo配置为
{
"secret": "SECRET",
"admin_password": "PASSWORD",
"admin_secret": "ADMIN-SECRET",
"api_key": "API-KEY",
"engine": "memory",
"admin": true,
"debug": true,
"log_level": "debug"
}
当前行为
- url 它已成功重定向到 https,其他项目可以很好地使用 ssl 配置
- 所有目录路径均已检查并正确无误
- 但是它说
404 page not found
- 当我在浏览器上尝试时
centrifugo.MY-HOST.com
确实显示了这个 404 错误 - 当我尝试使用
websocat
库(从服务器外部)时websocat ws://centrifugo.MY-HOST.com/connection/websocket
它说WebSocketError: Received unexpected status code. Error running
- 当我尝试使用
websocat
库时(从服务器内部,我的意思是通过 ssh 连接)websocat ws://localhost:8000/connection/websocket
它挂起...(我相信正在等待消息) - centrifugo 服务器启动并侦听端口 8000,用 netstat 检查并主管说
running
- 我在 centrifugo 配置和虚拟主机中将
127.0.0.1
更改为localhost
,将 documentRoot 添加到 apache 项目的路径中,但什么都没有...
我做错了什么?
算了,是我配置supervisor的错误。我有这个:
[program:centrifugo]
command=sudo /var/www/centrifugo-server/centrifugo
autostart=true
autorestart=true
stderr_logfile=/var/log/centrifugo.error.log
stdout_logfile=/var/log/centrifugo.output.log
我放置了带有完整路径的配置文件并删除了 sudo,效果非常好
command=/var/www/centrifugo-server/centrifugo --config=/var/www/centrifugo/config.json
我把它留在这里,以防对任何人有帮助
无论如何,如果有人知道如何翻译虚拟主机上的平衡器配置,那部分仍然缺失,谢谢