我想创建一个简单的聊天。我不是服务器管理的专家。所以我有个关于ngnix和faye的问题。
我使用ngnix +客运作为我的生产服务器。我有一个液滴的数字海洋,并希望部署我的应用程序。因此,对于部署,我使用正式的乘客教程https://www.phusionpassenger.com/library/install/nginx/install/oss/trusty/
对于模型回调,我使用faye-rails宝石。就像faye-rails说的,如果我使用乘客,我需要使用这个配置
config.middleware.use FayeRails::Middleware, mount: '/faye', :timeout => 25, server: 'passenger', engine: {type: Faye::Redis, host: 'localhost'} do
map '/announce/**' => SomeController
end在我的开发本地主机:3000聊天工作非常快。但是当我部署它时,它的工作非常慢(响应间隔为5到60秒)。我不知道怎么修理它。
在我的/etc/ngnix/sites-enabled/myapp.conf中,我使用了以下配置:
server {
listen 80;
server_name server_ip;
# Tell Nginx and Passenger where your app's 'public' directory is
root /project_path_to_public;
# Turn on Passenger
passenger_enabled on;
passenger_ruby /ruby_wrapper_path;
}我需要升级我的/etc/ngnix/sites-enabled/myapp.conf以及如何升级吗?或者我需要做什么?
发布于 2016-01-15 15:01:05
目前,我正在开发的应用程序上使用Faye和Redis。这不是问题当前设置的直接解决方案,而是我已经实现的另一种方法。下面是我的nginx配置,然后我让Faye在服务器上的屏幕上通过rackup运行。
/etc/nginx/sites启用/application.conf.nginx:
server {
listen 80;
listen [::]:80;
server_name beta.application.org;
# Tell Nginx and Passenger where your app's 'public' directory is
root /var/www/application/current/public;
# Turn on Passeger
passenger_enabled on;
passenger_ruby /usr/local/rvm/gems/ruby-2.2.1/wrappers/ruby;
rails_env production;
location ~* ^/assets/ {
# Per RFC2616 - 1 year maximum expiry
# http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
expires 1y;
add_header Cache-Control public;
add_header Last-Modified "";
add_header ETag "";
break;
}
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream websocket {
server 127.0.0.1:9292;
}
server {
listen 8020;
location / {
proxy_pass http://127.0.0.1:9292/push;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}这个链接应该为它的工作方式提供一点洞察力。https://chrislea.com/2013/02/23/proxying-websockets-with-nginx/
您还可以参考Faye github,以获得与乘客一起设置它的一些指导。
此外,如果您遵循数字海洋教程的初始服务器设置,并最终启用您的防火墙,请确保您允许您有Faye/websockets运行的端口。(参见此处配置基本防火墙:新Ubuntu 14.04服务器的其他建议步骤 )
我的另一种方法是在服务器上的单独屏幕上运行Faye。在ubuntu服务器上管理屏幕所需的几个命令是:
screen -S <pick screen name> (new screen)
screen -ls (lists screens)
screen -r <screen number> (attach screen)
to quit from a screen, ctrl + a THEN "d" (detach screen)运行新屏幕后,使用rackup:rackup faye.ru -s thin -E production在屏幕上运行Faye服务器
请注意,使用此选项,每次您重新启动数字海洋服务器(即,如果您创建一个屏幕截图作为备份),您将需要创建一个新屏幕并再次运行faye服务器;但是,使用类似Daemon之类的东西可以更好地解决这个问题(我只是还没有实现它.)。前往Github,查找FooBarWidget/daemon_控制器。
如果你还有其他问题,请告诉我,我会尽力帮忙的!
https://stackoverflow.com/questions/34810587
复制相似问题