标签:
致敬那些愿意去帮助别人的人
从字面意义上来看Forbidden不就是禁止访问,很自然的就应该想会权限问题嘛。不错,确实如此。Nginx的权限主要是Nginx要去访问其他资源才会出现。
index.html
或者index.php
。
#user liujb
worker_processes 1;
error_log /Users/liujb/logs/nginx/error.log notice;
events {
worker_connections 256;
}
http {
server {
listen 80;
server_name localhost;
root /Users/liujb/Dropbox/Code/mis-dev/;
index index.html index.php;
error_page 500 502 503 504 /50x.html;
location /static {
add_header Access-Control-Allow-Origin *;
}
location / {
if (!-e $request_filename) {
rewrite ^/(auth|crm|kefu|cms|fist|orange|citest)(.*)$ /$1/index.php last;
}
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
...
}
...
}
可以看出并未指定Nginx运行用户,注意下user配置,root要访问的目录是 /Users/liujb/Dropbox/Code/mis-dev
? nginx git:(master) ps aux | grep nginx | grep -v grep
nobody 7062 0.0 0.0 2465944 680 ?? S 10:02PM 0:00.00 nginx: worker process
root 7061 0.0 0.0 2465944 472 ?? Ss 10:02PM 0:00.00 nginx: master process nginx
可以看出Nginx的master进程是root用户在运行,而work进程是nobody用户在运行。
? Code ll mis-dev
total 0
drwxr-xr-x@ 8 liujb staff 272B Oct 14 10:21 auth
drwxr-xr-x@ 9 liujb staff 306B Feb 13 2015 citest
drwxr-xr-x@ 7 liujb staff 238B Sep 18 20:18 crm
drwxr-xr-x@ 8 liujb staff 272B Oct 26 11:53 fist
drwxr-xr-x@ 7 liujb staff 238B Jun 16 15:36 orange
drwxr-xr-x@ 10 liujb staff 340B Sep 15 13:04 scripts
drwxr-xr-x@ 18 liujb staff 612B Oct 29 17:44 static
drwxr-xr-x@ 3 nobody staff 102B Oct 27 10:49 upload
看得出非组内用户也是能读能执行的。所以权限是ok的。
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's
group
; will be used.
user = nobody
group = nobody
? nginx git:(master) ps aux | grep php-fpm | grep -v grep
liujb 7367 0.0 0.0 2457984 3144 s001 S+ 10:13PM 0:00.05 vim /etc/php-fpm.conf
nobody 7160 0.0 0.0 2471668 692 ?? S 10:02PM 0:00.00 php-fpm
nobody 7159 0.0 0.0 2470644 692 ?? S 10:02PM 0:00.00 php-fpm
root 7158 0.0 0.0 2470644 892 ?? Ss 10:02PM 0:00.03 php-fpm
master是root用户,work是nobody用户
总之需要保障
另外用到的命令有
这三个命令是Unix上边分别更改文件所属用户权限,所属组的权限以及文件权限。可以参考
标签:
原文地址:http://www.cnblogs.com/liujb/p/5142796.html