连接到上游时 nginx 错误:(13:权限被拒绝)

2024-02-09

我正在使用 ubuntu 14.04 LTS 的 google 计算引擎虚拟机上运行带有 puma、capistrano 和 nginx 的 Rails 应用程序。

我的 nginx 在外部 IP 上运行。当我访问它时,我在日志中收到两个 nginx 错误:

2016/02/03 11:58:07 [info] 19754#0: *73 client closed connection while waiting for request, client: ###.##.##.###, server: 0.0.0.0:443

2016/02/03 11:58:07 [crit] 19754#0: *74 connect() to unix:///home/my-user-name/apps/my-web-app/shared/tmp/sockets/my-web-app-puma.sock failed (13: Permission denied) while connecting to upstream, client: ###.##.##.###, server: , 
request: "GET / HTTP/1.1", upstream: "http://unix:///home/my-user-name/apps/my-web-app/shared/tmp/sockets/my-web-app-puma.sock:/", host: "###.###.###.###"

注意:最后一个 ###.###.###.### 是运行代码的 google 计算虚拟机的外部 IP。我相信前两个 IP 是我的家庭 IP。

我努力了:setsebool httpd_can_network_connect on正如这里所建议的:(13:权限被拒绝)连接到上游时:[nginx] https://stackoverflow.com/questions/23948527/13-permission-denied-while-connecting-to-upstreamnginx它返回了:setsebool: SELinux is disabled.但问题仍然存在。

我看过(13:权限被拒绝)连接到上游时:[nginx] https://stackoverflow.com/questions/23948527/13-permission-denied-while-connecting-to-upstreamnginx也是如此,但似乎有特殊之处uwsgi

这是我的 nginx.conf

upstream puma {
  server unix:///home/my-user-name/apps/my-web-app/shared/tmp/sockets/my-web-app-puma.sock;
}
server {
  listen 80 default_server deferred;
  listen 443 ssl;
  # server_name example.com;
  ssl_certificate /etc/ssl/my-web-app/my-web-app.com.chained.crt;
  ssl_certificate_key /etc/ssl/my-web-app/my-web-app.key;
  root /home/my-web-app/apps/my-web-app/current/public;
  access_log /home/my-user-name/apps/my-web-app/current/log/nginx.access.log;
  error_log /home/my-user-name/apps/my-web-app/current/log/nginx.error.log info;
  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }
  try_files $uri/index.html $uri @puma;
  location @puma {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://puma;
  }
  error_page 500 502 503 504 /500.html;
  client_max_body_size 10M;
  keepalive_timeout 10;
}

我运行 nginxsudo service nginx restart然后我运行 puma:RACK_ENV=production bundle exec puma -p 3000它返回:

Puma starting in single mode...
* Version 2.14.0 (ruby 2.1.7-p400), codename: Fuchsia Friday
* Min threads: 0, max threads: 16
* Environment: production
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop

EDIT 1

有人建议我在 unix 上运行 puma 而不是 tcp 3000,以便它与 nginx 匹配

我尝试通过以下命令在 unix 上运行 puma:

RACK_ENV=production bundle exec puma -d -b unix:///tmp/my-web-app.sock --pidfile /tmp/puma.pid

这给出了:

Puma starting in single mode...
* Version 2.14.0 (ruby 2.1.7-p400), codename: Fuchsia Friday
* Min threads: 0, max threads: 16
* Environment: production
* Daemonizing...

它读取了上面的文本,但它并没有停留,命令提示符立即再次出现,尽管末尾有“...”。

这个命令似乎不起作用,所以如果有人可以建议如何在 unix 而不是 tcp 3000 上运行 puma,那么我可以完成该建议。 (虽然我怀疑在与 puma 有关的任何事情之前可能会发生配置 nginx 问题)

EDIT 2正在附加 puma.rb

#!/usr/bin/env puma
directory '/home/my-user-name/apps/my-web-app/current'
rackup "/home/my-user-name/apps/my-web-app/current/config.ru"
environment 'production'
pidfile "/home/my-user-name/apps/my-web-app/shared/tmp/pids/puma.pid"
state_path "/home/my-user-name/apps/my-web-app/shared/tmp/pids/puma.state"
stdout_redirect '/home/my-user-name/apps/my-web-app/current/log/puma.error.log', '/home/my-user-name/apps/my-web-app/current/log/puma.access.log', true
threads 2,8
bind 'unix:///home/my-user-name/apps/my-web-app/shared/tmp/sockets/my-web-app-puma.sock'
workers 1
preload_app!
on_restart do
  puts 'Refreshing Gemfile'
  ENV["BUNDLE_GEMFILE"] = "/home/my-user-name/apps/my-web-app/current/Gemfile"
end
on_worker_boot do
  ActiveSupport.on_load(:active_record) do
    ActiveRecord::Base.establish_connection
  end
end

EDIT 3

我现在尝试直接在端口 80 上运行 Rails 服务器。我输入:rvmsudo rails server -p 80它返回:

=> Booting Puma
=> Rails 4.2.4 application starting in development on http://localhost:80
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Puma 2.14.0 starting...
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://localhost:80
Exiting
/home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/puma/binder.rb:233:in `initialize': Address already in use - bind(2) for "localhost" port 80 (Errno::EADDRINUSE)
        from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/puma/binder.rb:233:in `new'
        from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/puma/binder.rb:233:in `add_tcp_listener'
        from (eval):2:in `add_tcp_listener'
        from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/rack/handler/puma.rb:33:in `run'
        from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/rack-1.6.4/lib/rack/server.rb:286:in `start'
        from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/railties-4.2.4/lib/rails/commands/server.rb:80:in `start'
        from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:80:in `block in server'
        from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `tap'
        from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `server'
        from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
        from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

EDIT 4

如果我运行 sudo service nginx stop 然后运行rvmsudo rails server -p 80它再次返回:

=> Booting Puma
=> Rails 4.2.4 application starting in development on http://localhost:80
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Puma 2.14.0 starting...
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://localhost:80

这意味着这种方法是不正确的,因为没有 nginx,当我访问外部 IP 时,它现在不会返回任何内容The server refused the connection.与原来相反:

We're sorry, but something went wrong.

If you are the application owner check the logs for more information.

如果有人知道如何防止原来的错误,任何建议将不胜感激。

EDIT 5原来的问题仍然存在,但谁能告诉我这是 https 问题还是 ssl 问题?

EDIT 6

我尝试直接在 80 上运行 puma,但在 80 上出现权限错误。

I try: RACK_ENV=production bundle exec puma -p 80并得到:

Puma starting in single mode...
* Version 2.14.0 (ruby 2.1.7-p400), codename: Fuchsia Friday
* Min threads: 0, max threads: 16
* Environment: production
* Listening on tcp://0.0.0.0:80
/home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/puma/binder.rb:233:in `initialize': Permission denied - bind(2) for "0.0.0.0" port 80 (Errno::EACCES)
        from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/puma/binder.rb:233:in `new'
        from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/puma/binder.rb:233:in `add_tcp_listener'
        from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/puma/binder.rb:98:in `block in parse'
        from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/puma/binder.rb:84:in `each'
        from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/puma/binder.rb:84:in `parse'
        from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/puma/runner.rb:119:in `load_and_bind'
        from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/puma/single.rb:79:in `run'
        from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/puma/cli.rb:215:in `run'
        from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/gems/puma-2.14.0/bin/puma:10:in `<top (required)>'
        from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/bin/puma:23:in `load'
        from /home/my-user-name/apps/my-web-app/shared/bundle/ruby/2.1.0/bin/puma:23:in `<main>'

我认为这是因为80端口比其他端口具有更高的权限造成的。于是,我跑了sudo RACK_ENV=production bundle exec puma -p 80但这刚刚返回:Your Ruby version is 1.9.3, but your Gemfile specified 2.1.7


我和你遇到了同样的错误,我找到了解决方案,但不知道它是否正确。 更改文件的第一行/etc/nginx/nginx.conf

user www-data;
to
user root;

然后使用以下命令重新启动 nginx:

service nginx restart OR systemctl restart nginx

WARNING:这将运行您的网络服务器root用户。切勿在生产环境中执行此操作,因为它允许 Web 服务器进程完全访问您的系统。如果 Web 服务器进程遭到破坏,攻击者将可以不受限制地访问您的整个服务器。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

连接到上游时 nginx 错误:(13:权限被拒绝) 的相关文章

  • 遵循 http://ruby.railstutorial.org/ 教程时出现 RSpec 错误

    我到处搜索但似乎找不到解决方案 我一直在关注有关的教程http ruby railstutorial org http ruby railstutorial org 我在第 3 章中尝试使用 rspec spec 执行测试 但是我不断收到以
  • Rails 4:资产未在生产中加载

    我正在尝试将我的应用程序投入生产 但图像和 CSS 资源路径不起作用 这是我目前正在做的事情 图像资源位于 app assets images image jpg 样式表位于 app assets stylesheets style css
  • Rails 控制台无法运行

    rbenv 红宝石版本 2 6 6 导轨版本 5 1 4 我正在较旧的代码库中工作 ruby 2 6 6 rails 5 4 1 这是我每天使用的代码库 我必须通过 rbenv 下载一个新的 ruby 版本作为单独的存储库 这样做在我的旧代
  • 多重要求和允许强参数rails 4

    在下面的情况下 我尝试使用强参数 我想要求email address password并允许remember me fields 但像下面这样使用它只允许最后一行在方法示例中 在下面的情况下 它只需要params permit rememb
  • (Rails) Assert_Select 的烦人警告

    有谁知道如何让assert select在rake测试期间不输出所有那些讨厌的html警告 你知道 就像这样的东西 ignoring attempt to close body with div opened at byte 1036 li
  • Rails/Nginx 中的超时——最佳实践

    我正在开发一个应该在 Nginx 服务器上运行的 Rails 应用程序 根据输入 应用程序可能需要很长时间来处理请求 或者在出现错误时挂起 因此我想防止进程永远运行 除了确保客户端收到超时信号的 Nginx 配置之外 我想我可能仍然需要确保
  • 浏览器关闭时 Omniauth 会话过期

    在我的 Rails 3 应用程序中 我使用 Omniauth 进行用户身份验证部分 fb twitter 实际上我遵循这个 https github com RailsApps rails3 mongoid omniauth https g
  • Rails 4 使用 ajax、jquery、:remote => true 和 respond_to 渲染部分

    使用 AJAX 动态渲染页面以响应提交的表单似乎很常见 其他类似的问题都没有集中于如何以一般方式做到这一点 我能找到的关于这个主题的最好的博客文章在这里 http www gotealeaf com blog the detailed gu
  • nginx 上的多个网站和可用网站

    通过 nginx 的基本安装 您的sites available文件夹只有一个文件 default 怎么样sites available文件夹的工作原理以及如何使用它来托管多个 单独的 网站 只是为了添加另一种方法 您可以为您托管的每个虚拟
  • Rails Windows Vagrant 响应时间非常慢

    我在跑 Vagrant 1 7 1 Rails 4 1 4 Thin 1 6 1 Windows 7 每个静态文件的发送时间都超过一秒 在我的 PC 上加载一个页面可能需要大约 20 秒 而在同事的 Linux 机器上则只需瞬间 有一些帖子
  • 将rails_admin 与rails_api 结合使用

    我最初将此发布为Rails api GitHub 上的问题 https github com sferik rails admin issues 2617 但由于不活跃 我现在将其发布在这里 我正在尝试使用rails admin使用 Rai
  • 从父应用程序重新打开 Rails 3 引擎类

    就目前而言 您无法重新打开引擎中包含的引擎类 app只需在父应用程序的目录中添加相同的类即可 app目录 例如 my engine app controllers users controller rb my app app control
  • Ruby on Rails 服务器在 HTTPS POST 请求期间崩溃

    我正在尝试与你沟通城市飞艇API http urbanairship com docs push html broadcast使用 ROR Web 应用程序 在我的控制器中 我有以下代码 require net http require n
  • 让 Rails 生产在端口 80 上运行

    我正在尝试让我的 Rails 应用程序在生产模式下运行 但遇到了一些困难 我正在使用 Passenger 和 apache 并运行 Ubuntu 12 04 我已经配置和创建了生产数据库 并设置了乘客 状态如下 rvmsudo passen
  • 将查询字符串参数作为表单发布的一部分发送

    有没有办法捕获查询字符串并将其作为表单帖子的一部分发送 我正在使用 Rails 2 3 5 我的用户所在的页面有多个查询字符串参数 在此页面上 他们将提交一份表格 在接收帖子的操作中 我想知道这些查询字符串参数是什么 显然 它们不是作为邮件
  • Rails 中的嵌套布局

    Rails 3 2 中可以嵌套布局吗 我想创建 application html erb 使用的通用布局 并允许应用程序中的几个视图使用它 我找到了嵌套布局 https github com eric nested layoutsruby
  • 高效地重新安排 ActiveJob (resque/sidekiq)

    我正在玩Rails 4 2应用程序使用ActiveJob受支持resque sidekiq用于电子邮件安排 当用户创建时事通讯活动时 会创建一个新作业并安排在特定日期 这一切都很好 但是当用户更改交货日期时会发生什么 在这种情况下 每个作业
  • 即使路由存在,Rspec 命名空间路由规范也会失败

    我在用着rspec rails 2 8 1 and 导轨3 1 3 我正在尝试测试 Admin ZonesController 的路由 我已经通过运行验证了浏览器中存在该路由rake routes 我没有使用 ActiveRecord 如果
  • RSpec:如何在静态方法上使用should_receive?

    我在 lib gcm rb 中有一个模块 require net http require uri module GCM def self dispatch message reg ids data url URI parse GCM UR
  • rake db 问题:迁移 -

    我无法为 Ruby on Rails 设置 MySQL 数据库 设置数据库并确保 config database yml 文件匹配后 我遇到了以下错误消息 U Rails alpha gt rake db migrate trace in

随机推荐

  • 匹配标准 10 位电话号码的正则表达式

    我想为支持以下格式的标准美国电话号码编写正则表达式 其中 表示任意数字 到目前为止我想出了以下表达方式 1 9 d 2 d 3 d 4 d 3 s d 3 d 4 1 9 d 2 s d 3 s d 4 1 9 d 2 d 3 d 4 分别
  • 在Python中初始化固定大小的数组[重复]

    这个问题在这里已经有答案了 我想知道如何初始化一个数组 或列表 尚未填充值 以具有定义的大小 例如在 C 中 int x 5 declared without adding elements 我如何在 Python 中做到这一点 您可以使用
  • 给定组合时如何计算索引(字典顺序)

    我知道有一种算法允许给定数字组合 无重复 无顺序 计算字典顺序的索引 这对于我的应用程序加快速度非常有用 例如 combination 10 5 1 1 2 3 4 5 2 1 2 3 4 6 3 1 2 3 4 7 251 5 7 8 9
  • Ember 数据模型重新加载导致 {{each}} 中的项目被删除/插入回来 - 丢失当前状态

    我怎样才能防止itemView在迭代控制器时被删除并重新渲染回原位arrangedContent 如果观察到的模型的属性没有改变值 下面是使用博客文章的简短版本App Post作为示例模型 控制器 sortProperties create
  • 使用“C”执行 API 将 sqlite3 表导出到文件中

    我在 fedora 14 中使用 sqlite3 版本 3 6 23 1 我可以使用这样的命令提示符将表导出到文件中 sqlite3 data db sqlite gt output sample txt sqlite gt select
  • 如何使 TeamCity 构建出现在 TFS 构建资源管理器中?

    我们使用 TFS 2010 进行源代码控制和项目管理 使用 TeamCity 6 0 执行构建和构建报告 测试人员的 CI 和日常部署 在 TeamCity 中设置 TFS 源标签以匹配内部版本号非常简单 但我找不到将其链接回 TFS Bu
  • 使用 osmosis 将 POSTGIS 表转换为 .OSM

    我正在使用 osmosis 0 42 和 PostGIS 2 0 1 并且我正在尝试将一些 postGIS 表导出到 OSM xml 文件 我使用 read pgsql 命令从 postgis 读取 而不是 read apidb 因为它在连
  • 自我类型和特质子类有什么区别?

    特质的自我类型A trait B trait A this B gt 说 A不能混合到一个不扩展的具体类中B 另一方面 如下 trait B trait A extends B 说 任何 具体或抽象 类混合A也会混入B 这两个说法不是说的是
  • 如何基于一个 xcode 项目构建精简版和完整版 iPhone 应用程序?

    我不想维护两套代码 我只需要限制 Lite 版本中的一些功能并在其上添加一些广告即可 怎么做 创建多个目标 您可以通过右键单击目标并选择获取信息来改变构建配置 从那里 你可以做一些事情 比如改变Info plist文件它正在查看 执行诸如将
  • 我们可以在 PWA 应用程序中使用 SQLite 数据库吗

    我正在创建渐进式网络应用程序应用程序 我想将用户信息存储在本地设备中 那么 我该如何做到这一点 如何存储用户登录信息 以便他不必一次又一次登录 浏览器没有 SQLite 您可以使用更接近的方法索引数据库 https caniuse com
  • asm编译器中的二进制表达式

    我正在尝试使用逻辑和符号 执行 if 语句 这是我想要做的 asm字节码中的 y堆栈具有值0和1 我想得到结果 在我们的例子中 逻辑与 不会出现在 if 语句中 我已经尝试过 Opcodes IFEQ 和 Opcodes IFNE 指令 但
  • Chain animator设置 android 动画

    对于android新手 我想做一些流畅的动画 我的设备上有一个包含效果的文件 每个效果都是一个动画 该文件告诉我何时播放效果以及效果持续时间 问题是我无法链接 animatorSet dynmacily AnimatorSet mainAn
  • 限制使用 git log --decorate 显示的引用

    我目前使用的主存储库有 3 个标准遥控器 本地备份 我的开发合作伙伴的工作站和托管存储库 我们有 3 或 4 个分支大部分时间都处于活动状态 其中一个是 master 我全天定期监控分支机构 使用 git log graph oneline
  • jquery 摇动效果和 margin-auto

    有一点烦恼这个 震动效果示例 http jsfiddle net PHPsycho mwVkm 1 在 Firefox 中如果我省略该行 this css margin left this position left 然后该框会向左移动而不
  • ` throw 'foo'` 、 ` throw Error('foo')` 、 `throw new Error('foo')` 之间有什么区别?

    我见过 3 种在 JavaScript 中引发错误的不同方式 throw message throw Error message throw new Error message 它们之间有什么区别 注意 我知道类似的问题 1 https s
  • 读取字节数限制

    Does fread一次可以读取的字节数有限制吗 或者我可以读取我想要添加到指针中的任何尺寸 例如 我可以使用fread读取一次50MB的文件并将其装入char指针吗 理论上 是的 它可以读取任意数量的字节 最多可达size t 这是一个u
  • 如何使用 C++ 在 OS X 中打开“打开文件”对话框?

    我正在开发一个使用 OpenGL 和 C 的应用程序 该应用程序解析文件中的一些结构化输入并以图形方式显示它 我想在应用程序加载时启动一个 打开文件 对话框 以允许用户选择他们想要显示的文件 我无法在网络上找到我需要的东西 有没有办法在 C
  • 无法在 C# 中访问 Amazon SQS 消息属性

    我有一个进程创建 SQS 消息并将它们放置在 SQS 队列中 另一个进程读取这些消息并根据消息正文的内容和属性执行某些逻辑 我可以在 SQS 队列上成功创建一条带有正文和属性的消息 但在读回消息属性时遇到问题 我确信我的消息创建过程是正确的
  • scrapy中403错误的解决方法

    我是 scrapy 的新手 我制作了 scrapy 项目来废弃数据 我正在尝试从网站上抓取数据 但收到以下错误日志 2016 08 29 14 07 57 scrapy INFO Enabled item pipelines 2016 08
  • 连接到上游时 nginx 错误:(13:权限被拒绝)

    我正在使用 ubuntu 14 04 LTS 的 google 计算引擎虚拟机上运行带有 puma capistrano 和 nginx 的 Rails 应用程序 我的 nginx 在外部 IP 上运行 当我访问它时 我在日志中收到两个 n