簡體   English   中英

Ruby on Rails應用程序返回403錯誤在ubuntu中使用unicorn和nginx進行部署?

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

我在Ubuntu中部署了ruby on rails應用程序。 我已經用RAILS_ENV=production rails s測試了我的應用程序,一切正常。 但是使用unicornnginx ,出現403錯誤。

這是錯誤日志:

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

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;
}

采取一看一致的 ,功能齊全的Nginx的配置示例。 此配置描述了通過Unix套接字在Unicorn上運行的Rails應用程序的 Nginx代理。 現在您准備修復配置!:-)

為了從上面的示例中使用此配置,請將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
}

無論如何,當代理后面的一切正常工作時,調試代理要容易得多。

以防萬一,請確保您已預編譯資產;-)

$ RAILS_ENV=production bundle exec rake assets:precompile

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM