无法访问日志文件。请确保path / to / production.log存在且可写

时间:2017-06-19 12:43:06

标签: ruby-on-rails ruby apache azure passenger

我面临以下问题,在Azure平台(CentOS)中使用Apache - Passenger启动Rails应用程序:

App 18106 stdout:
App 18106 stderr: Rails Error:
Unable to access log file. Please ensure that /path/to/production.log exists and is writable (ie, make it writable for user and group: chmod 0664 /path/to/production.log).
The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.

App 18106 stdout:
[ 2017-06-19 11:37:13.5635 18014/7f7826db7700 age/Cor/App/Implementation.cpp:304 ]: Could not spawn process for application /var/www/my_rails_app: An error occurred while starting up the preloader.
Error ID: f684beca
Error details saved to: /tmp/passenger-error-JB9Dio.html
Message from application: could not connect to server: Permission denied
    Is the server running on host "localhost" (::1) and accepting
    TCP/IP connections on port 5432?
could not connect to server: Permission denied
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 5432?
(PG::ConnectionBad)
/usr/local/rvm/gems/ruby-2.3.1/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:654:in `initialize'
/usr/local/rvm/gems/ruby-2.3.1/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:654:in `new'
/usr/local/rvm/gems/ruby-2.3.1/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:654:in `connect'
/usr/local/rvm/gems/ruby-2.3.1/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'

我已尝试chmod 0664 /path/to/production.log,但错误没有改变,如上所述。

相同的设置在AWS中运行良好。

Apache conf.d个文件:

/etc/httpd/conf.d/my_app.conf

<VirtualHost *:80>
  ServerName localhost
  DocumentRoot /var/www
  ErrorLog logs/rails_app_error_log
  <Directory "/var/www/">
          Allow from all
          Options -MultiViews
  </Directory>

  Alias /my_rails_app /var/www/my_rails_app/public/
  <Location /my_rails_app>
          PassengerBaseURI /my_rails_app
          PassengerAppRoot /var/www/my_rails_app
  </Location>
  <Directory /var/www/my_rails_app/public/ >
          Options Indexes ExecCGI FollowSymLinks MultiViews
          Order allow,deny
          Allow from all
          AllowOverride all
  </Directory>
  <IfModule mod_passenger.c>
    PassengerUser  apache
    PassengerGroup apache
  </IfModule>
</VirtualHost>

/etc/httpd/conf.d/passenger.conf

LoadModule passenger_module /usr/lib64/httpd/modules/mod_passenger.so
 <IfModule mod_passenger.c>
   PassengerRoot /usr/local/rvm/gems/ruby-2.3.1/gems/passenger-5.1.2
   PassengerDefaultRuby /usr/local/rvm/gems/ruby-2.3.1/wrappers/ruby
 </IfModule>

我还设置了chown -R apache:apache my_rails_app

注意:如果我在不使用Apache的情况下以独立模式运行Passenger,那么一切正常。

我搜索了所有其他相关帖子并试图避开日志中的could not connect to server: Permission denied,但似乎没有任何效果。

<小时/>

解决方案:

我认为问题出在SElinux上,运行以下命令后问题得到了解决:

  

/usr/sbin/setsebool -P httpd_can_network_connect 1

2 个答案:

答案 0 :(得分:1)

根据Passenger + Apache and Ruby的乘客官方故障排除The Rails application reports that it's unable to start because of a permission error,我认为问题是由您的Rails应用程序目录的权限引起的。

因此,请先通过ps -ef|grep apache检查您的apache流程的所有者,然后检查所有者&amp;通过ls -l <path of rails>对您的Rails应用程序目录进行分组,如下所示。

$ ps -ef |grep apache
root      7226     1  0 16:10 ?        00:00:00 /usr/sbin/apache2 -k start
www-data  7229  7226  0 16:10 ?        00:00:00 /usr/sbin/apache2 -k start
www-data  7230  7226  0 16:10 ?        00:00:00 /usr/sbin/apache2 -k start
<user>    7756 30915  0 16:12 pts/2    00:00:00 grep --color=auto apache

$ ls -l
total 4
drwxrwxr-x 13 <user> <group> 4096 Jun 20 16:22 myrails

然后尝试更改所有者&amp;使用rootwww-data通过chown -R <OWNER>:<GROUP> myrails rootwww-data对您的Rails应用程序目录进行分组所有权。

作为参考,你可以参考一个类似的SO线程What permissions are needed for apache Passenger

希望它有所帮助。

答案 1 :(得分:0)

运行

chmod 777 <directory_with_logs>

这将为您提供整个目录的执行/读/写权限。问题可能在于目录,而不是文件。

您可以进一步使用这些数字来微调app。