16 Jan 2015
## nginx.conf中的http{}代码段中增加: include /usr/local/nginx/conf/vhost/nginx-vhost.conf; ## 在上面指定的目录"/usr/local/nginx/conf/vhost"创建nginx-vhost.conf文件,并增加以下字段: server { listen 80; server_name www.301r.com 301r.com; root /data/www; index index.html index.htm index.php; location ~ \.php$ { root /data/www; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name; include fastcgi_params; } }
错误信息:
# curl -xlocalhost:80 www.301r.com -I HTTP/1.1 403 Forbidden Server: nginx/1.6.2 Date: Sun, 18 Jan 2015 14:20:25 GMT Content-Type: text/html Content-Length: 168 Connection: keep-alive
解决方案:
尝试一:
给网站目录修改属主为nginx的用户nobody
此用户可在nginx.conf里增加user username;来改变
尝试二: 给网站目录增加777属性
解决方案:在index字段增加index.php
解决方案:
增加以下字段
location ~ \.php$ { root /data/www; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name; #这里很关键 include fastcgi_params; } }
实际解决方案:
应该把相应目录的属主设置为php-fpm用户,此用户的设置在php-fpm.conf文件中的www程序池里。
[www] ... user = php-fpm group = php-fpm chown -R php-fpm .
思考:apache没遇到这个问题,是因为php提供给了apache一个模块,apache的用户自然就是php模块的用户,所以在apache中只需要把apache的用户(也相当于php的授权用户)daemon设置为此目录的属主就可以了。
实际解决方案:
my.cnf中我指定的是/tmp/mysql.socket,所以做了个软连接取名为/tmp/mysql.sock