同样碰到 403 问题了,请帮看看 直接 rails s 启动可以正常 ip 访问 感觉 server_name pattest.domain1.com;并未生效,通过http://pattest.domain1.com:3000/http://pattest.domain2.com:3000/403或者访问都是
配置: cat /etc/nginx/sites-enabled/example.com.conf server { #listen 80 default; listen 3000; server_name pattest.domain1.com; # 这里填写你真实域名 root /var/www/pattest.domain1.com/pat/public; passenger_ruby /home/lpxiao/.rvm/rubies/ruby-2.1.0/bin/ruby; passenger_enabled on; }
nginx log: 2014/05/23 23:04:36 [error] 35484#0: *4 directory index of "/var/www/pattest.domain1.com/pat/public/" is forbidden, client: 123.114.36.75, server: pattest.domain1.com, request: "GET / HTTP/1.1", host: "pattest.domain1.com:3000"
ror public: drwxr-xr-x 3 lpxiao lpxiao 4096 May 23 22:33 public
给个思路
ps -ef| grep nginx
或者看 /etc/nginx/nginx.conf
的 user 配置sudo -u <nginx_user> ls /var/www/pattest.domain1.com/pat/public/
来检查是否真的 permission denysudo chown <nginx_user>: -R /var/www/pattest.domain1.com/pat/public/
这样还搞不定的话,赶紧去学一下 linux 吧..
shell
ps -ef| grep nginx
root 45240 1 0 21:02 ? 00:00:00 nginx: master process /usr/sbin/nginx
www-data 45241 45240 0 21:02 ? 00:00:00 nginx: worker process
www-data 45242 45240 0 21:02 ? 00:00:00 nginx: worker process
www-data 45243 45240 0 21:02 ? 00:00:00 nginx: worker process
www-data 45244 45240 0 21:02 ? 00:00:00 nginx: worker process
lpxiao 45454 43362 0 21:23 pts/1 00:00:00 grep --color=auto nginx
cat /etc/nginx/nginx.conf | grep user
user www-data;
2.
sudo -u www-data ls /var/www/pattest.domain1.com/pat/public/
[sudo] password for lpxiao:
404.html 422.html 500.html assets favicon.png robots.txt
3.
sudo chown www-data: -R public/
[sudo] password for lpxiao:
ll | grep public
drwxr-xr-x 3 www-data www-data 4096 May 24 21:11 public/
log,偶发报 favicon.ico,不知啥原因
2014/05/24 21:33:10 [error] 45241#0: *12 open() "/var/www/pattest.domain1.com/pat/public/favicon.ico" failed (2: No such file or directory), client: 123.114.36.75, server: pattest.domain1.com, request: "GET /favicon.ico HTTP/1.1", host: "pattest.domain2.cn"
2014/05/24 21:33:44 [error] 45241#0: *16 directory index of "/var/www/pattest.domain1.com/pat/public/" is forbidden, client: 123.114.36.75, server: pattest.domain1.com, request: "GET / HTTP/1.1", host: "pattest.domain1.com"
2014/05/24 21:34:38 [error] 45241#0: *16 directory index of "/var/www/pattest.domain1.com/pat/public/" is forbidden, client: 123.114.36.75, server: pattest.domain1.com, request: "GET / HTTP/1.1", host: "pattest.domain1.com"
2014/05/24 21:35:49 [error] 45241#0: *18 directory index of "/var/www/pattest.domain1.com/pat/public/" is forbidden, client: 123.114.36.75, server: pattest.domain1.com, request: "GET / HTTP/1.1", host: "pattest.domain1.com"
cat /etc/nginx/nginx.conf
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##
# include /etc/nginx/naxsi_core.rules;
##
# Phusion Passenger config
##
# Uncomment it if you installed passenger or passenger-enterprise
##
# passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
# passenger_ruby /usr/bin/ruby;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
# mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
# }
按文档加的
cat /etc/nginx/sites-enabled/example.com.conf
server {
listen 80 default;
#listen 3000;
server_name pattest.domain1.com;
root /var/www/pattest.domain1.com/pat/public;
passenger_ruby /home/lpxiao/.rvm/rubies/ruby-2.1.0/bin/ruby;
passenger_enabled on;
}
还有个怪事,我有两个域名 a.com,b.com,pat.a.com,pat.b.com 都解析到这个 ip,但是 nginx 里只配 pat.a.com,两个访问都是 403,也都导向 root 目录了,nginx 没过滤我的域名?
关于这事,我每次都反复教别人,如果你弄不清 Linux 环境用户权限的事情,那就简单点儿!项目代码、数据库、Log、上传文件…通通放在用户的 Home 目录,Nginx 用那个用户跑
##
# Phusion Passenger config
##
# Uncomment it if you installed passenger or passenger-enterprise
##
# passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
搜了好久找到这个帖子,加了这个
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
之后第一次觉得能看到 RoR 报错也是一种幸福。。