[英]Trying to run Faye websocket on Apache using a proxy
我正在嘗試在生產環境中使用Rails的瘦服務器上使用Faye gem,但我無法使其工作。 我正在使用apache 2.4和ws_tunnel也啟用了代理模塊。 我的設置如下。
Apache配置
<VirtualHost *:443>
ServerName mysite.example.com
ServerAlias mysite.example.com
DocumentRoot /var/www/html/mysite/current/public
SSLEngine on
SSLCertificateFile "/etc/httpd/conf/keys/ServerCertificate.cer"
SSLCertificateKeyFile "/etc/httpd/conf/keys/example.com.key"
SSLCertificateChainFile "/etc/httpd/conf/keys/CACertificate-1.cer"
RewriteEngine On
SSLProxyEngine On
ProxyRequests off
ProxyPreserveHost on
ProxyPass /faye !
ProxyPassReverse /faye !
ProxyPass / balancer://thinservers/
ProxyPassReverse / balancer://thinservers/
<Proxy *>
Require all granted
</Proxy>
<Location /faye>
ProxyPass ws://localhost:9292
ProxyPassReverse ws://localhost:9292
</Location>
RequestHeader set X_FORWARDED_PROTO 'https'
# Custom log file locations
ErrorLog /etc/httpd/logs/error-unilever.log
CustomLog /etc/httpd/logs/access-unilever.log combined
</VirtualHost>
Faye.ru文件
require 'faye'
Faye::WebSocket.load_adapter('thin')
app = Faye::RackAdapter.new(:mount => '/faye', :timeout => 25)
run app
我正在使用以下命令啟動faye
rackup faye.ru -E production -s thin
這樣我就可以通過在瀏覽器中輸入以下URL來訪問faye.js。
https://mysite.example.com/faye/faye.js
但是當我輸入https://mysite.example.com/faye/時 ,我得到以下結果
Sure you're not looking for /faye ?<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>500 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator at
root@localhost to inform them of the time this error occurred,
and the actions you performed just before this error.</p>
<p>More information about this error may be available
in the server error log.</p>
</body></html>
這很奇怪,因為我只得到“當然你不是在尋找/ faye?” 在發展中。
我在application.js中稱為Faye
client = new Faye.Client("https://mysite.example.com/faye/faye")
而且我得到了一個錯誤
POST https://mysite.example.com/faye/faye 400 (Bad Request)
我還嘗試在代理設置中使用wss協議,並將我的證書路徑設置為瘦以從SSL開始,但沒有任何效果。
我假設由於代理或ws_tunnel模塊可能會發生這種情況,因為當我從服務器中的shell運行以下命令時
curl http://localhost:9292
我只得到“當然你不是在尋找/ faye?” 信息。
有沒有人來過這樣的事情?
如果有人能幫助我,我將不勝感激。
提前致謝。
對於那些有同樣問題的人,我的建議是無論你使用的是哪個版本的Apache,只需毫不猶豫地將其更改為nginx。 配置和運行它非常容易。
我正在使用以下配置為我的app命名示例。 正確設置nginx后,其他一切都運行良好。
希望這有助於某人
# app: example
# locally running on port 7000
upstream example {
server 127.0.0.1:7000;
server 127.0.0.1:7001;
}
# Faye is set to run on port 9292
upstream example_socket{
server 127.0.0.1:9292;
}
server {
# listen 80 if it's a non SSL site
listen 443;
server_name www.example.com;
location /faye {
proxy_pass http://example_socket;
# Including common configurations
include /etc/nginx/conf.d/proxy.conf;
include /etc/nginx/conf.d/proxy_socket.conf;
}
location / {
root /var/www/vhost/example/current/public;
proxy_pass http://example;
# Including common configurations
# can be found on Internet easily
include /etc/nginx/conf.d/proxy.conf;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.