apache 未写入日志文件(乘客)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1787583/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 18:25:51  来源:igfitidea点击:

Log files not being written to (Passenger)

ruby-on-railslinuxapachepassengerselinux

提问by asdfasdfasdfasdf

Locally, my app runs fine on and writes to its logs.

在本地,我的应用程序运行良好并写入其日志。

My production server is running CentOS with an Apache server running Passenger. When trying to debug, I noticed my log files were not being written to. First thing I did was chmod 0666 them, and when I found out that didn't work I looked at my apache log. I found this: Rails Error: Unable to access log file. Please ensure that /var/www/vhosts/mysite.com/rails/exp/releases/20091124020342/log/production.log exists and is chmod 0666. The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.

我的生产服务器运行 CentOS,Apache 服务器运行Passenger。在尝试调试时,我注意到我的日志文件没有被写入。我做的第一件事是 chmod 0666 他们,当我发现这不起作用时,我查看了我的 apache 日志。我发现了这个:Rails 错误:无法访问日志文件。请确保 /var/www/vhosts/mysite.com/rails/exp/releases/20091124020342/log/production.log 存在并且是 chmod 0666。日志级别已提升到 WARN 并且输出定向到 STDERR 直到问题出现是固定的。

(Note: I am deploying with capistrano)

(注意:我正在使用 capistrano 进行部署)

Anyway, I Googled around and found people saying it's an SELinux issue, so I looked on passenger's docs and found this: http://www.modrails.com/documentation/Users%20guide.html#_my_rails_application_8217_s_log_file_is_not_being_written_to

无论如何,我搜索了一下,发现有人说这是 SELinux 问题,所以我查看了乘客的文档并找到了这个:http: //www.modrails.com/documentation/Users%20guide.html#_my_rails_application_8217_s_log_file_is_not_being_written_to

which basically says do this: chcon -R -h -t httpd_sys_content_t /path/to/your/rails/app

基本上说这样做: chcon -R -h -t httpd_sys_content_t /path/to/your/rails/app

However, when I fill in the proper path I get: Operation not supported.

但是,当我填写正确的路径时,我得到:不支持操作。

Pretty stumped...any ideas?

很困惑……有什么想法吗?

回答by coreypurcell

What are the results of "ls -l" on your log file? On Ubuntu I have to make sure that the acl's are correct on the log files. I usually solve that by using

日志文件中“ls -l”的结果是什么?在 Ubuntu 上,我必须确保日志文件中的 acl 是正确的。我通常通过使用来解决这个问题

sudo chown -R deploy:deploy /path/to/app

Deploy is the user that passenger runs in.

Deploy 是乘客跑进来的用户。

回答by Shyam Habarakada

I ran into the same issue with my ubuntu 10.x server. Here's what I learned while troubleshooting.

我的 ubuntu 10.x 服务器遇到了同样的问题。这是我在故障排除时学到的东西。

  • As mentioned previously and in the docs, Passenger runs the rails ruby processes as the owner of the config/environment.rb file. Unless you have done something special, this is typically the same as the owner of your entire rails application directory. In the case of a capistrano deployment, this is the capistrano user.
  • If environment.rb is owned by root (most likely because you are deploying as root) passenger runs the rails processes as 'nobody'
  • 正如前面和文档中提到的,Passenger 作为 config/environment.rb 文件的所有者运行 rails ruby​​ 进程。除非您做了一些特殊的事情,否则这通常与整个 rails 应用程序目录的所有者相同。在 capistrano 部署的情况下,这是 capistrano 用户。
  • 如果 environment.rb 由 root 拥有(很可能是因为您以 root 身份部署),则乘客以“nobody”身份运行 rails 进程

You can see which user the processes are run as via the top command (or any number of other techniques).

您可以通过 top 命令(或任意数量的其他技术)查看进程以哪个用户身份运行。

In either case -- mine happend to be the latter -- if the rails processes cannot write to the log files, nothing shows up in the logs (duh). Rails will ignore this permission denied error and try to process the requests as normally.

在任何一种情况下——我的恰好是后者——如果 rails 进程无法写入日志文件,日志中不会显示任何内容(废话)。Rails 将忽略此权限被拒绝错误并尝试正常处理请求。

The solution is to ensure that the rails ruby processes are running as the same user that owns your rails deployment, config/environment.rb file and the logs directory and files.

解决方案是确保 rails ruby​​ 进程以拥有 rails 部署、config/environment.rb 文件以及日志目录和文件的同一用户身份运行。

This can be either deplyment configuration step to chown the files and directories in question or configuring apache and telling it to run the ruby process as a specific user (say, root instead of nobody). Running as root is obviously not recommended, but if you are doing that for whatever reasons, and need to see rails logs properly written to, you can do this by adding the following

这可以是部署有问题的文件和目录的部署配置步骤,也可以是配置 apache 并告诉它以特定用户身份运行 ruby​​ 进程(例如,root 而不是 nobody)。显然不建议以 root 身份运行,但是如果您出于某种原因这样做,并且需要查看正确写入的 rails 日志,您可以通过添加以下内容来实现

# in /etc/apache2/apache2.conf
PassengerDefaultUser root 

If you are not deploying as root (which is the case on another server I have), the typical scenario should be that the rails app directory is owned by that non-root-user, and passenger should run the rails processes as that same user. And everything should just work.

如果您不是以 root 身份部署(在我拥有的另一台服务器上就是这种情况),典型情况应该是 rails 应用程序目录归该非 root 用户所有,并且乘客应该以同一用户身份运行 rails 进程. 一切都应该正常工作。

[1] http://www.modrails.com/documentation/Users%20guide%20Apache.html#_the_rails_application_reports_that_it_8217_s_unable_to_start_because_of_a_permission_error

[1] http://www.modrails.com/documentation/Users%20guide%20Apache.html#_the_rails_application_reports_that_it_8217_s_unable_to_start_because_of_a_permission_error