环境:ubuntu 12.10 x64 server 背景: 根据http://ruby-china.org/wiki/install-rails-on-ubuntu-12-04-server 这个 wiki 在 ununtu 上部署 rails 4 nginx 和 passenger 都正确安装没有提示错误“Nginx with Passenger support was successfully installed.” nginx 的配置文件也是按照 wiki 的教程配置的,不过就多了 passenger_root 和 passenger_ruby:
passenger_root /home/shhuqi/.rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.16;
passenger_ruby /home/shhuqi/.rvm/wrappers/ruby-2.0.0-p247/ruby;
当前遇到两个问题: 1、用 sudo /etc/init.d/nginx stop 无法停止 nginx 服务(当前我用 sudo /opt/nginx/sbin/nginx -s stop 才能停止)
2、访问域名一直是 ngnix 的 403 页面,貌似 passenger 没有启动?rails 服务也没有启动?
各位求解啊
第二个问题,已经解决,我把 nginx 配置文件 (nginx.conf) 中的下面 5 行去掉,rails 就能够起来了,不然 rails 死活起不来,一直是 nginx 的 403 页面:
server {
# 此处用于防止其他的域名绑定到你的网站上面
listen 80 default;
return 403;
}
这个什么原因啊,求解?@huacnlee 大神这个能否解答一下啊?
你的注释不是写清了,# 此处用于防止其他的域名绑定到你的网站上面
吗
然后你要让 nginx.conf 里的 user 行的用户和组和你的 rails 原码的所有者是一样的,而且这个用户对文件夹有读写权限
你现在用 ps aux | grep nginx 应该看到用户是 nobody 这是因为源码和 nginx.conf 的 user 不一致,nginx 实例的执行用户(变成了 nobody) 权限不足
#6 楼 @huacnlee rails 不能起来的 nginx.conf
user shhuqi;
worker_processes 1;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
passenger_root /home/shhuqi/.rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.16;
passenger_ruby /home/shhuqi/.rvm/wrappers/ruby-2.0.0-p247/ruby;
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 64;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
client_max_body_size 50m;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_disable "msie6";
server {
# 此处用于防止其他的域名绑定到你的网站上面
listen 80 default;
return 403;
}
server {
listen 80;
server_name www.mysite.com;
root /home/shhuqi/www/enterpriseshow/public;
passenger_enabled on;
rails_env production;
location ~ ^(/assets) {
access_log off;
expires max;
}
}
}
rails 可以起来的 nginx.conf
user shhuqi;
worker_processes 1;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
passenger_root /home/shhuqi/.rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.16;
passenger_ruby /home/shhuqi/.rvm/wrappers/ruby-2.0.0-p247/ruby;
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 64;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
client_max_body_size 50m;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_disable "msie6";
server {
listen 80;
server_name www.mysite.com;
root /home/shhuqi/www/enterpriseshow/public;
passenger_enabled on;
rails_env production;
location ~ ^(/assets) {
access_log off;
expires max;
}
}
}
麻烦看看,多谢!
#7 楼 @ZombieCoder 都是在 shhuqi 这个用户下的,rails 代码也在这个用户下,nginx 配置文件中也是 shhuqi 这个用户的
可以看这里 http://nginx.org/en/docs/http/request_processing.html
In this configuration nginx tests only the request’s header field “Host” to determine which server the request should be routed to. If its value does not match any server name, or the request does not contain this header field at all, then nginx will route the request to the default server for this port. In the configuration above, the default server is the first one — which is nginx’s standard default behaviour. It can also be set explicitly which server should be default, with the default_server parameter in the listen directive:
server { listen 80 default_server; server_name example.net www.example.net; ... }
The default_server parameter has been available since version 0.8.21. In earlier versions the default parameter should be used instead.