【发布时间】:2016-05-11 04:38:10
【问题描述】:
我正在尝试运行一个 Rails 应用程序。我按照以下说明操作:http://luugiathuy.com/2014/11/setup-nginx-puma-on-ubuntu/ 设置服务器。
但是,当我走到最后,特别是:puma -e production -d -b unix:///tmp/app_name.sock --pidfile /tmp/puma.pid 运行它后,我得到了响应:
Puma starting in single mode...
* Version 2.16.0 (ruby 2.1.7-p400), codename: Midwinter Nights Trance
* Min threads: 0, max threads: 16
* Environment: production
* Daemonizing...
外部IP一直返回nginx错误:
We're sorry, but something went wrong.
If you are the application owner check the logs for more information.
所以,在其他地方,我尝试了:
RACK_ENV=production bundle exec puma -p 3000
而且,这似乎做得更多,我得到了:
Puma starting in single mode...
* Version 2.15.3 (ruby 2.1.7-p400), codename: Autumn Arbor Airbrush
* Min threads: 0, max threads: 16
* Environment: production
Rails Error: Unable to access log file. Please ensure that /home/myusername/myappname/log/production.log exists and is writable (ie, make it writable for user and group: chmod 0664 /home/myusername/myappname/log/production.log). The log level has bee
n raised to WARN and the output directed to STDERR until the problem is fixed.
** [Bugsnag] Bugsnag exception handler 3.0.0 ready, api_key=#####################
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
但是外部网页返回同样的nginx错误。
我应该如何进行?似乎事情正在运行,但 puma 和 nginx 只是不说话?
编辑 1
I did: `sudo chmod -R 0777 /home/myunsername/appname/log/`
Then:
$RACK_ENV=production bundle exec puma -p 3000
而且,现在输出如下,外部 IP 上的 nginx 响应保持不变。
Puma starting in single mode...
* Version 2.15.3 (ruby 2.1.7-p400), codename: Autumn Arbor Airbrush
* Min threads: 0, max threads: 16
* Environment: production
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
现在,两种方法:RACK_ENV=production bundle exec puma -p 3000 和 puma -e production -d -b unix:///tmp/web-app.sock --pidfile /tmp/puma.pid 创建 puma 进程似乎不与 nginx 通信但不返回任何错误。
EDIT 2检查日志
我跑了:
cat log/production.log
它返回:
I, [2016-02-02T##:##:##.###### #28802] INFO -- : ** [Bugsnag] Bugsnag exception handler 3.0.0 ready, api_key=####################
EDIT 2.5 检查更多日志 我跑了:
tail -f /var/log/nginx/error.log
它返回:
2016/02/02 11:09:52 [emerg] 28220#0: unknown directive "tream" in /etc/nginx/sites-enabled/web-appname.com:1
2016/02/02 11:10:26 [emerg] 28273#0: unknown directive "tream" in /etc/nginx/sites-enabled/web-appname.com:1
这些错误是由于我的文件缺少前 3 个字符而导致的,该错误已得到修复。总之:我上面列出的日志中似乎没有任何错误给我任何提示。
编辑 3
我目前的猜测是我错误地设置了我的 /etc/nginx/sites-available/myapp.com 文件。这是我使用的所有命名。
目前命名为:web-app.com,url就是ip地址,比如说https://104.199.155.166/。我的应用程序位于名为 web-app
的文件夹中upstream web-app {
server unix:///tmp/web-app.sock;
}
server {
listen 80;
server_name web-app; # change to match your URL
root /home/myusername/web-app/public; # change to match your rails app public folder
location / {
proxy_pass http://web-app; # match the name of upstream directive which is defined in line 1
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
}
location ~* ^/assets/ {
# Per RFC2616 - 1 year maximum expiry
expires 1y;
add_header Cache-Control public;
# Some browsers still send conditional-GET requests if there's a
# Last-Modified header or an ETag header even if they haven't
# reached the expiry date sent in the Expires header.
add_header Last-Modified "";
add_header ETag "";
break;
}
}
编辑 4
我对上述配置文件做了很多修改,但我所做的一切都没有改变。我目前拥有我认为正确的配置。我很茫然,如果有任何建议,我将不胜感激。
小问题:如果有其他用户在同一个虚拟机上,他们可能安装和配置不同的 nginx,这会导致问题吗?
【问题讨论】:
-
首先修复日志的权限错误。
-
您是否检查了production.log的访问权限为mentioend in error
-
您能check the NGiNX logs 并在问题中添加任何相关行吗?在这种情况下,错误可能发生在 NGiNX 中,甚至在您怀疑的请求被传递给 Puma 之前。
-
@max 感谢您提供有关在何处查找日志的信息,我已在编辑 2.5 中添加了该信息
标签: ruby-on-rails ruby-on-rails-3 nginx puma