gpt4 book ai didi

ruby-on-rails - 无法访问日志文件。请确保path/to/Production.log存在并且可写

转载 作者:行者123 更新时间:2023-12-02 23:00:30 25 4
gpt4 key购买 nike

我在 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

注意:如果我在独立模式下运行 Passenger 而不使用 Apache,那么一切都会正常工作。

我已经搜索了所有其他相关帖子,并尝试避免日志中的无法连接到服务器:权限被拒绝,但似乎没有任何效果。


解决方案:

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

/usr/sbin/setsebool -P httpd_can_network_connect 1

最佳答案

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

所以请首先通过 ps -ef|grep apache 检查您的 apache 进程的所有者,然后通过 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

然后尝试使用 root 更改 Rails 应用程序目录的所有者和组所有权或www-data通过chown -R <OWNER>:<GROUP> myrailsrootwww-data .

作为引用,有一个类似的SO线程What permissions are needed for apache Passenger您可以引用一下。

希望有帮助。

关于ruby-on-rails - 无法访问日志文件。请确保path/to/Production.log存在并且可写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44630894/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com