Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 502 rails应用程序的nginx出现错误_Ruby On Rails_Nginx_Unicorn - Fatal编程技术网

Ruby on rails 502 rails应用程序的nginx出现错误

Ruby on rails 502 rails应用程序的nginx出现错误,ruby-on-rails,nginx,unicorn,Ruby On Rails,Nginx,Unicorn,我正在centos上使用rails、unicorn和nginx构建一个应用程序。我对做服务器端的事情还很陌生,但我正在尝试让应用程序运行起来 这是我的nginx default.conf文件: upstream app { # Path to Unicorn SOCK file, as defined previously server unix:/tmp/unicorn.rqm3.sock fail_timeout=0; } server { listen 808

我正在centos上使用rails、unicorn和nginx构建一个应用程序。我对做服务器端的事情还很陌生,但我正在尝试让应用程序运行起来

这是我的nginx default.conf文件:

upstream app {
    # Path to Unicorn SOCK file, as defined previously
    server unix:/tmp/unicorn.rqm3.sock fail_timeout=0;
}

server {


    listen 8080;
    server_name localhost;

    root /www/rqm3/;

    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;
}  
这是我的独角兽文件:

# Set the working application directory
# working_directory "/path/to/your/app"
working_directory "/www/rqm3"

# Unicorn PID file location
# pid "/path/to/pids/unicorn.pid"
pid "/www/rqm3/pids/unicorn.pid"

# Path to logs
# stderr_path "/path/to/log/unicorn.log"
# stdout_path "/path/to/log/unicorn.log"
stderr_path "/www/rqm3/log/unicorn.log"
stdout_path "/www/rqm3/log/unicorn.log"

# Unicorn socket
listen "/tmp/unicorn.[app name].sock"
listen "/tmp/unicorn.rqm3.sock"

# Number of processes
# worker_processes 4
worker_processes 2

# Time-out
timeout 30
这是我的nginx错误日志

2015/08/06 14:37:44 [crit] 24375#0: *30 connect() to unix:/tmp/unicorn.rqm3.sock failed (13: Permission denied) while connecting to upstream, client: 192.168.2.213, server: localhost, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/unicorn.rqm3.sock:/", host: "192.168.1.29:8080"

在我的Rails 5+Puma+Nginx设置中,我只在从
www.example.com
api.example.com
时看到
502

如果您的浏览器正在发送
选项
请求,而您的服务器返回
502
错误,则表明您的服务器是跨源的。然后,您的浏览器将首先发送一个飞行前
OPTIONS
请求,以查看发送敏感数据是否安全。该请求应该在到达Rails之前通过Nginx、Unicorn和Rack。Rails清理您的请求。如果允许您的来源,Rack将
200
返回到您的浏览器,然后浏览器可以发送实际的
GET
POST
PATCH
DELETE
您想要发送的请求

要在中打开,可以使用此初始值设定项:

# config/initializers/cors.rb
# https://github.com/cyu/rack-cors

Rails.application.config.middleware.insert_before 0, Rack::Cors do
  allow do
    origins 'example.com'

    resource '*',
      headers: :any,
      methods: [:get, :post, :put, :patch, :delete, :options, :head]
  end
end

在我的Rails 5+Puma+Nginx设置中,我只在从
www.example.com
api.example.com
时看到
502

如果您的浏览器正在发送
选项
请求,而您的服务器返回
502
错误,则表明您的服务器是跨源的。然后,您的浏览器将首先发送一个飞行前
OPTIONS
请求,以查看发送敏感数据是否安全。该请求应该在到达Rails之前通过Nginx、Unicorn和Rack。Rails清理您的请求。如果允许您的来源,Rack将
200
返回到您的浏览器,然后浏览器可以发送实际的
GET
POST
PATCH
DELETE
您想要发送的请求

要在中打开,可以使用此初始值设定项:

# config/initializers/cors.rb
# https://github.com/cyu/rack-cors

Rails.application.config.middleware.insert_before 0, Rack::Cors do
  allow do
    origins 'example.com'

    resource '*',
      headers: :any,
      methods: [:get, :post, :put, :patch, :delete, :options, :head]
  end
end

愚蠢的问题,但你正在启动rails(rack)应用程序吗?另外,
listen”/tmp/unicorn.[app name].sock“
行在你的unicorn文件中是一个输入错误吗?应用程序启动了,并且有问题的行是直接从教程中复制的,我将在没有该行的情况下尝试它,看看它是否有任何更改。只是添加了错误日志,似乎我没有正确的权限,但我已将其设置为“775”愚蠢的问题,但你正在启动rails(rack)应用程序吗?另外,
listen”/tmp/unicorn.[app name].sock“
行在你的unicorn文件中是一个输入错误吗?应用程序启动了,并且有问题的行是直接从教程中复制的,我将在没有该行的情况下尝试它,看看它是否有任何更改。只是添加了错误日志,似乎我没有正确的权限,但我已将其设置为“775”