微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ubuntu – Nginx Passenger Rails – 403禁止

有很多人有相同或类似的问题,但他们都解决了不同的解决方案.我很难搞清楚我的设置有什么问题.

我刚刚安装了Nginx 1.4.1,Passenger 4.0.7,Ruby 2.0.0p247和Rails 4.0.0.

注意:

>我已经安装了Nginx @ / home / deployer / Nginx
>我正在使用rubyenv
>我有www.example.com的CNAME记录,指向myapp.cloud.com

我在〜/ Nginx / conf / Nginx.conf的末尾添加了这个块

server {
  listen 80;
  server_name www.example.com;
  root /home/deployer/sites/www.example.com/public;
  passenger_enabled on;
}

我在/home/deployer/sites/www.example.com上有一个公共符号链接,指向/ home / deployer / src / myapp / gateway / public /

我有两个问题:

>如果我没有为我的rails应用程序设置认的根路由,那么当我访问我的站点的根目录时,我看不到标准的Rails Welcome页面.相反,我继续获得403 Forbidden页面.但是,如果我在公共文件夹中添加index.html,我确实会看到当我去http://www.example.com/时呈现的页面
>如果我将认根路由设置为controller#action,那么当我转到我的站点的根目录时,我看不到正在呈现的控制器操作.相反,这是我在〜/ Nginx / logs / error.log中遇到的错误

2013/07/08 19:57:05 [error] 34157#0: *1 directory index of
"/home/deployer/sites/www.example.com/public/" is forbidden,client: 76.XX.XX.29,server: www.example.com,request: "GET / HTTP/1.1",host: "www.example.com"

只是在这种情况下,这是我完整的Nginx.config文件

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/Nginx.pid;


events {
    worker_connections  1024;
}


http {
    passenger_root /home/deployer/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/passenger-4.0.7;
    passenger_ruby /home/deployer/.rbenv/versions/2.0.0-p247/bin/ruby;

    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.PHP${
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.PHP${
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.PHP;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files,if Apache's document root
        # concurs with Nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-,name-,and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;

    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_timeout  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers   on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

    server {
      listen 80;
      server_name www.example.com;
      root /home/deployer/sites/www.example.com/public;
      passenger_enabled on;
   }
}

解决方法

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐