简体   繁体   English

Ruby on Rails应用程序返回403错误在ubuntu中使用unicorn和nginx进行部署?

[英]Ruby on rails application return 403 error deploy in ubuntu with unicorn and nginx?

I deploy a ruby on rails application in ubuntu. 我在Ubuntu中部署了ruby on rails应用程序。 I have test my application with RAILS_ENV=production rails s , everything is ok. 我已经用RAILS_ENV=production rails s测试了我的应用程序,一切正常。 But with unicorn and nginx , I got 403 error. 但是使用unicornnginx ,出现403错误。

here is the error log: 这是错误日志:

2015/01/21 16:04:48 [error] 12432#0: *1 directory index of "/home/roger/ruby_workspace/hello_app/public/" is forbidden, client: 192.168.44.1, server: , request: "GET / HTTP/1.1", host: "192.168.44.131"

ll /home/roger/ruby_workspace/hello_app/public/ return ll / home / roger / ruby​​_workspace / hello_app / public / return

drwxrwxr-x  2 roger roger 4096  1月 13 14:55 ./
drwxrwxr-x 14 roger roger 4096  1月 19 22:30 ../
-rwxrwxr-x  1 roger roger 1564  1月 13 14:55 404.html*
-rwxrwxr-x  1 roger roger 1547  1月 13 14:55 422.html*
-rwxrwxr-x  1 roger roger 1477  1月 13 14:55 500.html*
-rwxrwxr-x  1 roger roger    0  1月 13 14:55 favicon.ico*
-rwxrwxr-x  1 roger roger  202  1月 13 14:55 robots.txt*

this is part of my nginx.conf: 这是我的nginx.conf的一部分:

server {
    listen 80 default deferred;
    root /home/roger/ruby_workspace/hello_app/public/;
    try_files $uri/index.html $uri @hello_app;
    client_max_body_size 128M;
    keepalive_timeout 5;

    access_log logs/host.access.log main;

    location @hello_app {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header HOST $http_host;
        proxy_redirect off;
        #proxy_pass http://hello_app;
    }

    error_page 500 502 503 504 /500.html;
}

Take a look on this Nginx configuration example as consistent and fully functional. 采取一看一致的 ,功能齐全的Nginx的配置示例。 This config describes Nginx proxying of Rails app runing on Unicorn via Unix socket. 此配置描述了通过Unix套接字在Unicorn上运行的Rails应用程序的 Nginx代理。 Now you ready to fix your config!:-) 现在您准备修复配置!:-)

In order to use this config from example above, setup Unicorn to use socket (bit faster) or HTTP port. 为了从上面的示例中使用此配置,请将Unicorn设置为使用套接字 (速度更快)或HTTP端口。 And make sure Unicorn starts correctly. 并确保独角兽正确启动。 Only after that you may continue. 只有在那之后,您才能继续。

Please be sure @hello_app is correct upstream name in your config. 请确保@hello_app在您的配置中是正确的上游名称。 Currently it's definition is absent in your code: 目前,您的代码中没有它的定义:

upstream hello_app{
  # Update xxx.socket below:
  server unix:/home/roger/ruby_workspace/hello_app/tmp/sockets/xxx.socket fail_timeout=0;
  # Or use HTTP port here e.g.
  # server http://hello_app
}

Anyway it's much more easy to debug proxying, when everything behind it is working. 无论如何,当代理后面的一切正常工作时,调试代理要容易得多。

Just in case, make sure you have assets precompilled;-) 以防万一,请确保您已预编译资产;-)

$ RAILS_ENV=production bundle exec rake assets:precompile

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM