【问题标题】:Ruby on rails nginx , unicorn, capistrano vps hosting errorRuby on rails nginx、unicorn、capistrano vps 托管错误
【发布时间】:2014-08-01 09:56:15
【问题描述】:

您好,我正在学习如何在 VPS 中部署 rails 应用程序,我已按照https://coderwall.com/p/yz8cha 这个教程进行操作,一切正常,我遇到了一些错误并通过搜索网络纠正了它们,一切正常 capistrano 部署文件和文件夹到 VPS,如果我更改任何代码,然后在类型 cap deploy 之后它也会在 VPS 中更改,一切正常,终端中没有显示错误,但问题是 nginx 服务器没有运行(在初始阶段它显示它索引页面 - 欢迎使用 nginx),我不知道哪里可能出现问题,我必须做的任何帮助将不胜感激,,我正在使用 rails 4.1.4,ruby 2.1.2,capistrano(2.15.5)如果它的问题..

我不知道这里必须显示哪些代码如果您想查看我渴望向您展示的任何代码....这是我的 nginx.conf 文件

upstream unicorn {
  server unix:/tmp/unicorn.projectname.sock fail_timeout=0;
}

server {
    listen 80 default_server deferred;
  # server_name example.com;
  root /home/administrator/apps/testvps/current/public;

  location ^~ /assets/ {
    gzip_static on;
   expires max;
   add_header Cache-Control public;
   }

   try_files $uri/index.html $uri @unicorn;
   location @unicorn {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://unicorn;
  }

   error_page 500 502 503 504 /500.html;
   client_max_body_size 20M;
   keepalive_timeout 10;
 }

这是我在 VPS 终端中 nginx -t 时遇到的错误

nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log"            failed     (13: Permission denied)
2014/08/01 15:40:35 [warn] 5682#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
2014/08/01 15:40:35 [emerg] 5682#0: open() "/run/nginx.pid" failed (13: Permission denied)
nginx: configuration file /etc/nginx/nginx.conf test failed

【问题讨论】:

  • 将您的nginx.conf 文件内容粘贴到您的问题中
  • 是的 Raj,在启用 vps IN 站点时看到我的 nginx 文件夹时,rails 应用程序中有一个用于 nginx.conf 文件的链接文件,但如果我点击该文件,它会显示链接已损坏跨度>
  • 好的.. 让我知道nginx -t 命令的输出。在服务端运行
  • 发布了我从终端得到的命令

标签: ruby-on-rails nginx capistrano unicorn


【解决方案1】:

根据nginx -t显示的错误,用户没有写入nginx日志文件的权限。

尝试以root用户sudo nginx -t运行nginx -t,如果仍然显示权限错误,请尝试更新权限:

sudo chown -R www-data:www-data /var/log/nginx;
sudo chmod -R 755 /var/log/nginx;

编辑:

根据我们的讨论,您的 nginx 配置已成功设置。现在您在访问应用程序时看到空白页。

您需要将root 添加到您的routes.rb 文件中。 Rails 4 没有 public/index.html 文件。所以,你看到的是空白页。设置root后就可以看到你的主页了。

您的进一步疑问:

所以这是 nginx.conf 文件 root /home/administrator/apps/testvps/current/public;

我应该这样改变吗: root /home/administrator/apps/testvps/current;

不,nginx 应该查看应用程序的 public 目录。如routes.rb 中所述,将请求导航到root_path 是rails 的责任

【讨论】:

  • 我已经在我的服务器中执行了你的代码,是否需要重新启动我的服务器仍然是同样的错误?
  • 再次尝试nginx -t 并在评论中粘贴错误(如果有)。如果没有错误,则重新启动服务器
  • 我已经在我的服务器中执行了你的代码,我是否需要重新启动我的服务器仍然是同样的错误? ——
  • 好的..尝试重新启动...如果错误再次与/var/log/nginx的权限有关,请告诉我
猜你喜欢
  • 2015-04-12
  • 1970-01-01
  • 1970-01-01
  • 2011-04-14
  • 2015-05-03
  • 1970-01-01
  • 2016-05-04
  • 2012-12-20
  • 1970-01-01
相关资源
最近更新 更多