gpt4 book ai didi

ubuntu - Nginx + Passenger + Rails - 403 禁止

转载 作者:太空宇宙 更新时间:2023-11-03 16:50:13 24 4
gpt4 key购买 nike

有很多人遇到相同或相似的问题,但他们都用不同的解决方案解决了。我很难弄清楚我的设置有什么问题。

我刚刚安装了 Nginx 1.4.1、Passenger 4.0.7、Ruby 2.0.0p247 和 Rails 4.0.0。

注意:

  • 我已经安装了 nginx @ /home/deployer/nginx
  • 我正在使用 rubyenv
  • 我有一个 www.example.comCNAME 记录,它指向 myapp.cloud.com

我在 ~/nginx/conf/nginx.conf 的末尾添加了这个 block >

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 中有一个 public 符号链接(symbolic link)指向 /home/deployer/src/myapp/网关/公共(public)/

我有两个问题:

  1. 如果我没有为我的 Rails 应用程序设置默认的 root 路由,当我转到我的网站。相反,我一直收到 403 Forbidden 页面。但是,如果我在 public 文件夹中添加一个 index.html,当我访问 http://www.example.com 时,我会看到该页面正在呈现/

  2. 如果我将默认的 root 路由设置为 controller#action,当我转到我的根目录时,我看不到正在呈现的 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;
}
}

最佳答案

你不能那样使用符号链接(symbolic link)。参见 How Phusion Passenger detects whether a virtual host is a web application

关于ubuntu - Nginx + Passenger + Rails - 403 禁止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17535839/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com