Sinatra 应用程序在生产模式下出现 404 错误
我的生产设置如下:
- Ubuntu 10.10
- Rails 3.1.1
- Passenger 3.0.9
- Sinatra 1.3.1
- Apache 2.2.17
我已经在我的开发计算机上测试了我的应用程序,没有出现问题,但是当我部署到生产服务器时,我收到“找不到页面”显示错误(不是常见的 apache 错误)。
我可以使用rackup config.ru 运行而不会出现问题,因此假设它必须是apache/乘客问题,并且可能与路径相关。我现在厌倦了两个不同的服务器,都给出了相同的错误。
我的 config.ru 文件如下:
require 'rubygems'
require 'sinatra'
use Rack::ShowExceptions
#set :public_folder, File.expand_path(File.dirname(__FILE__) + "/public")
#set :views, File.expand_path(File.dirname(__FILE__) + "/views")
root_dir = File.dirname(__FILE__)
set :root, root_dir
disable :run
FileUtils.mkdir_p 'log' unless File.exists?('log')
log = File.new("log/sinatra.log", "a")
$stdout.reopen(log)
$stderr.reopen(log)
#use Rack::ShowExceptions
require File.dirname(__FILE__) + "/bin/hsloginapp"
run Sinatra::Application
我的虚拟主机文件:
<VirtualHost *:4090>
ServerName sinatra-demo.xxxxxxx.net
DocumentRoot "/var/www/html/hsloginapp/production/current/public"
<Directory /var/www/html/hsloginapp/public>
Order allow,deny
Allow from all
Options FollowSymLinks
</Directory>
</VirtualHost>
我的应用程序有点太复杂,无法将所有内容粘贴到此处,但如果需要,我很乐意粘贴部分内容。
我对简单的 sinatra 应用程序没有任何问题,因此感觉一切运行正常。现在已经在这上面花了四天了——这让我快要崩溃了。
甚至看不出这个 404 是从哪里来的。我在 sinatra.log 中看到的只是:
[16/Oct/2011 20:55:41] "GET / " 404 18 0.0008
我的公共文件夹中没有索引文件 - 尽管我的其他乘客/铁路应用程序中没有索引文件...
任何建议都非常感谢!
-- 更新 --
认为我的 apache 配置可能已被填充,我安装了 nginx 并得到相同的“未找到”页面。我的文件系统中似乎不存在它。
浏览我的 sinatra 日志,看起来像是 webrick 的启动 - 我不知道为什么?
2011-10-22 15:13:12] INFO WEBrick 1.3.1
[2011-10-22 15:13:12] INFO ruby 1.8.7 (2010-08-16) [x86_64-linux]
[2011-10-22 15:13:17] WARN TCPServer Error: Address already in use - bind(2)
== Someone is already performing on port 4990!
94.194.200.254 - - [22/Oct/2011 15:13:17] "GET / " 404 18 0.0636
94.194.200.254 - - [22/Oct/2011 15:13:18] "GET /favicon.ico " 404 18 0.0012
我想这就是问题所在?!需要帮助:)
-- 更新 2 --
刚刚在我的 nginx 错误日志中注意到系统正在尝试加载 public/index.html
*9 "/var/www/html/hotspotlogin/public/index.html" is not found (2: No such file or directory)
乘客/nginx 不应该知道在这里做什么吗?
My productions setup's as follows:
- Ubuntu 10.10
- rails 3.1.1
- Passenger 3.0.9
- Sinatra 1.3.1
- Apache 2.2.17
I have tested my app on my development machine without issue but when I deploy to my production server, I get a Page Not Found error displayed (not the usual apache one).
I can run using rackup config.ru without issue so assume it has to be an apache / passenger problem, and maybe path related. I have now tired on two different servers, both giving the same error.
My config.ru file is as follows:
require 'rubygems'
require 'sinatra'
use Rack::ShowExceptions
#set :public_folder, File.expand_path(File.dirname(__FILE__) + "/public")
#set :views, File.expand_path(File.dirname(__FILE__) + "/views")
root_dir = File.dirname(__FILE__)
set :root, root_dir
disable :run
FileUtils.mkdir_p 'log' unless File.exists?('log')
log = File.new("log/sinatra.log", "a")
$stdout.reopen(log)
$stderr.reopen(log)
#use Rack::ShowExceptions
require File.dirname(__FILE__) + "/bin/hsloginapp"
run Sinatra::Application
My virtual host file:
<VirtualHost *:4090>
ServerName sinatra-demo.xxxxxxx.net
DocumentRoot "/var/www/html/hsloginapp/production/current/public"
<Directory /var/www/html/hsloginapp/public>
Order allow,deny
Allow from all
Options FollowSymLinks
</Directory>
</VirtualHost>
My app's a bit too complicated to paste all here but am happy to paste parts if required.
I have no issues with a simple sinatra app and therefore feel as though things are running OK. Have now spent four days on this - it's driving me crackers.
Can't really even see where this 404 is coming from. All I can see in my sinatra.log is:
[16/Oct/2011 20:55:41] "GET / " 404 18 0.0008
I don't have an index file in my public folder - although I don't have one in an of my other passenger / rails apps...
Any suggestions greatly appreciated!!
-- UPDATE --
Thinking my apache config might have been stuffed, I installed nginx and get the same Not Found page. Which doesn't seem to exist anywhere in my file system.
Looking through my sinatra log, it looks like webrick's starting - I have no idea why though?
2011-10-22 15:13:12] INFO WEBrick 1.3.1
[2011-10-22 15:13:12] INFO ruby 1.8.7 (2010-08-16) [x86_64-linux]
[2011-10-22 15:13:17] WARN TCPServer Error: Address already in use - bind(2)
== Someone is already performing on port 4990!
94.194.200.254 - - [22/Oct/2011 15:13:17] "GET / " 404 18 0.0636
94.194.200.254 - - [22/Oct/2011 15:13:18] "GET /favicon.ico " 404 18 0.0012
I guess that's the issue?! Help needed :)
-- UPDATE 2 --
Just noticed in my nginx error log that the system's trying to load public/index.html
*9 "/var/www/html/hotspotlogin/public/index.html" is not found (2: No such file or directory)
Shouldn't passenger / nginx know what to do here??!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题可能是您没有正确设置乘客。
在 Apache 上,确保您在某处有此行:
在 nginx 上,您的配置应包含此行:
请注意,您正在尝试使用 WEBRick 运行 Sinatra,而不是上面日志示例中的 Rassenger/Apache(并且该端口不可用) )。要使用 Passenger 运行它,您必须编写 config.ru,因为 Passenger 对 Sinatra 一无所知。
The issue is probably that you don't have passenger set up properly.
On Apache, make sure you have this line somewhere:
On nginx, your config should include this line:
Note that you are trying to run Sinatra with WEBRick, not with Rassenger/Apache in the logs example up there (and that port is not available). For running it with Passenger, you will have to write a config.ru, since Passenger doesn't know a thing about Sinatra.