安装完各种环境以后,第二步要做的就是 让nginx 支持PHP
找到 nginx下的default.conf 找到
-
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
-
#
-
#location ~ \.php$ {
-
# root html;
-
# fastcgi_pass 127.0.0.1:9000;
-
# fastcgi_index index.php;
-
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
-
# include fastcgi_params;
-
#}
因为nginx默认没有关联PHP,所以此处
将其修改为
-
-
location ~ \.php$ {
-
root /usr/share/nginx/html;
-
fastcgi_split_path_info ^(.+\.php)(/.+)$;
-
fastcgi_pass 127.0.0.1:9000;
-
fastcgi_index index.php;
-
try_files $uri =403;
-
fastcgi_param SCRIPT_FILENAME $request_filename;
-
include fastcgi_params;
-
}
-
然后,将解析所有文件处 加上默认 index.php ,按照先后顺序决定优先解析那种文件
-
location / {
-
root /usr/share/nginx/html;
-
index index.html index.htm;
-
}
修改为
-
location / {
-
root /usr/share/nginx/html;
-
index index.php index.html index.htm;
-
}
这样 nginx就能解析PHP文件了
另外 此处可加上用socket方式执行php-fpm 来优化速度,具体方式为
找到 php-fpm.d/ 然后 修改其中的
将其改成
-
listen = /tmp/php-fcgi.sock
另外注意 权限问题,默认mode 是 0660 重启php-fpm会没办法读取 fcgi 需改成 0666
;listen.owner = php-fpm
;listen.group = php-fpm
listen.mode = 0666
然后 再在nginx解析PHP修改 fastcgi_pass 执行方式为socket
-
location ~ \.php$ {
-
root /usr/share/nginx/html;
-
fastcgi_split_path_info ^(.+\.php)(/.+)$;
-
fastcgi_pass unix:/tmp/php-fcgi.sock;
-
fastcgi_index index.php;
-
try_files $uri =403;
-
fastcgi_param SCRIPT_FILENAME $request_filename;
-
include fastcgi_params;
-
}
这样php-fpm就是以socket方式执行了
上传文件大小
vim /etc/nginx/nginx.conf
client_max_body_size 10M;
阅读(1952) | 评论(0) | 转发(0) |