我已经build立了nginx(下面的nginx.conf)和瘦。 nginx和瘦(2服务器)都在运行(我检查他们正在运行)。 我可以在rails公共目录(如index.html)中访问一个静态页面,但是如果我放入任何其他的url,我会得到一个由nginx生成的500页,“我们很抱歉,但出了问题。 任何帮助我做错了赞赏。 我想能够访问rails应用程序。
http { include /etc/nginx/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 /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 30; #gzip on; # Load config files from the /etc/nginx/conf.d directory # The default server is in conf.d/default.conf include /etc/nginx/conf.d/*.conf; #Rails app config here upstream Backend { server 127.0.0.1:3000; server 127.0.0.1:3001; } server { listen 80; server_name www.domain.com; rewrite ^/(.*) http://domain.com permanent; } server { listen 80; server_name domain.com; access_log /applications/RailsApp/log/access.log; error_log /applications/RailsApp/log/error.log; root /applications/RailsApp/public; # index index.html; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; if (-f $request_filename/index.html) { rewrite (.*) $1/index.html break; } if (-f $request_filename.html) { rewrite (.*) $1.html break; } if (!-f $request_filename) { proxy_pass http://Backend; break; } } }
}
这正是我的nginx.conf,除了domain.com这里是一个实际域的占位符。
在意识到错误来自rails而不是nginx或thin之后,通过在我的Rails应用程序中检查log / production.log来相当快地解决了这个问题。 我有两个问题。
首先,我的生产数据库在config / database.yml中的套接字是不正确的。 我不得不将它从不正确的套接字:tmp / mysql.sock更改为它在我的系统上的实际位置:socket:var / lib / mysql / mysql.sock。
在这之后,log / production.log中还有另一个错误,关于一个没有被预编译的css文件。 这是通过编辑config / environments / production.rb并将“config.assets.compile = false”更改为“config.assets.compile = true”来解决的。