2015-01-21 38 views
0

我在ubuntu上部署了一个ruby on rails应用程序。我已经用RAILS_ENV=production rails s测试我的应用程序,一切正常。但与unicornnginx,我得到了403错误。Ruby on Rails应用程序返回403错误部署在ubuntu与独角兽和nginx?

这里是错误日志:

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 /家庭/罗杰/ ruby​​_workspace/hello_app /公/返回

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* 

这是我的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; 
} 
+0

你知道你有你的应用程序目录'nginx'用户权限的权限? – 2015-01-21 08:26:27

+0

@Зелёный我怎么知道这个? – roger 2015-01-21 08:26:59

+0

我认为nginx也需要用户作为nginx.conf中的配置。 – Sanjiv 2015-01-21 08:28:26

回答

1

看看this Nginx配置示例如一致完全功能。此配置描述Nginx代理Rails应用程序运行在Unicorn通过Unix套接字。现在您准备好修复您的配置了!:-)

为了使用上面的示例中的配置,将Unicorn设置为使用套接字(比特更快)或HTTP端口。并确保独角兽正确启动。只有在此之后,你才能继续。

请确定@hello_app在您的配置中是正确的上游名称。目前,它的定义是在代码中缺席:

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 
} 

反正它更容易调试代理,在其背后一切工作。

以防万一,确保你拥有资产precompilled ;-)

$ RAILS_ENV=production bundle exec rake assets:precompile 
+0

谢谢,你确实帮了我一个日志,但你能告诉我什么是'xxx.socket',现在我的'/ home/roger/ruby​​_workspace/hello_app/tmp/sockets /'为空,我在[githq]中找不到它(https://github.com/gitlabhq/gitlabhq/tree/master/tmp/sockets) – roger 2015-01-23 06:20:52

+1

我已经知道什么是'xxx。 socket'通过这篇文章[配置Nginx和Unicorn](http://sleekd.com/general/configuring-nginx-and-unicorn/) – roger 2015-01-23 08:21:17

相关问题