我在网上尝试了很多建议,但没有任何效果。我让 unicorn 和 nginx 致力于在 CentOS 6.5 服务器上部署 ruby on Rails 应用程序。它以前有效,但现在当我尝试拉起该网站时,我收到了错误的网关错误。我正在使用的两个主要文件是 unicorn.rb 配置文件和 nginx 的 default.conf 文件。这些文件的位置是:/home/myuser/myApp/config/unicorn.rb 和 /etc/nginx/conf.d/default.conf。以下是它们包含的内容:
独角兽.rb
Set the working application directory
# working_directory "/path/to/your/app"
working_directory "/home/myuser/myApp"
# Unicorn PID file location
# pid "/path/to/pids/unicorn.pid"
pid "/home/myuser/myApp/pids/unicorn.pid"
# Path to logs
# stderr_path "/path/to/log/unicorn.log"
# stdout_path "/path/to/log/unicorn.log"
stderr_path "/home/myuser/myApp/log/unicorn.log"
stdout_path "/home/myuser/myApp/log/unicorn.log"
# Unicorn socket
# listen "/tmp/unicorn.[app name].sock"
listen "/home/myuser/myApp/tmp/unicorn.myApp.sock"
# Number of processes
# worker_processes 4
worker_processes 2
# Time-out
timeout 30
默认配置文件
upstream app {
# Path to Unicorn SOCK file, as defined previously
server unix:/home/myuser/myApp/tmp/unicorn.myApp.sock fail_timeout=0;
}
server {
listen 80;
server_name localhost;
# Application root, as defined previously
root /root/myApp/public;
try_files $uri/index.html $uri @app;
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
我正在尝试从 myuser 运行这些东西,所以我不想移动 unicorn 文件或 myApp。为了设置这个我遵循https://www.digitalocean.com/community/articles/how-to-deploy-rails-apps-using-unicorn-and-nginx-on-centos-6-5但更改了某些步骤的目录。我知道当我不更改目录时该教程会起作用,但我确实需要它在我的用户主目录中运行。任何帮助表示赞赏。
看起来问题出在nginx上。当查看 nginx error.log 时,我得到以下信息:
2014/03/05 14:53:04 [crit] 5756#0: *1 stat() "/home/myuser/myApp/public/tasks/index.html" failed (13: Permission d$
2014/03/05 14:53:04 [crit] 5756#0: *1 stat() "/home/myuser/myApp/public/tasks" failed (13: Permission denied), cli$
2014/03/05 14:53:04 [crit] 5756#0: *1 connect() to unix:/home/myuser/myApp/tmp/unicorn.myApp.sock failed (13: Per$
2014/03/05 14:53:04 [crit] 5756#0: *1 stat() "/home/myuser/myApp/public/500.html/index.html" failed (13: Permissio$
2014/03/05 14:53:04 [crit] 5756#0: *1 stat() "/home/myuser/myApp/public/500.html" failed (13: Permission denied), $
2014/03/05 14:53:04 [crit] 5756#0: *1 connect() to unix:/home/myuser/myApp/tmp/unicorn.myApp.sock failed (13: Per$
2014/03/05 14:53:04 [crit] 5756#0: *1 stat() "/home/myuser/myApp/public/favicon.ico/index.html" failed (13: Permis$
2014/03/05 14:53:04 [crit] 5756#0: *1 stat() "/home/myuser/myApp/public/favicon.ico" failed (13: Permission denied$
2014/03/05 14:53:04 [crit] 5756#0: *1 connect() to unix:/home/myuser/myApp/tmp/unicorn.myApp.sock failed (13: Per$
2014/03/05 14:53:04 [crit] 5756#0: *1 stat() "/home/myuser/myApp/public/500.html/index.html" failed (13: Permissio$
2014/03/05 14:53:04 [crit] 5756#0: *1 stat() "/home/myuser/myApp/public/500.html" failed (13: Permission denied), $
2014/03/05 14:53:04 [crit] 5756#0: *1 connect() to unix:/home/myuser/myApp/tmp/unicorn.myApp.sock failed (13: Per$
我在网上找到的解决方案之一是禁用 SELinux。我尝试过,但没有帮助。这些文件的权限均为 777,因此不应发生这种情况。有任何想法吗?