修改nginx配置,使其支持php

方式一:

yum install nginx #安装nginx

vim /etc/nginx/conf.d/test.conf

server {
    listen 80;
    #listen [::]:80;
    server_name 39.105.1.170;
    client_max_body_size 128m;#限制大小

    location / {
        charset  utf-8;
        root /var/www;
        index  index.html index.htm;
        }
     location ~ \.php$ {
        root           /var/www;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name;
        include        fastcgi_params;
    }
}

nginx -s reload #启动nginx

在/var/www新建两个文件,一个html文件,一个php文件


重启nginx服务

方式一:systemctl start
方式二:sudo /etc/init.d/nginx restart 这个不知道行不:nginx -s reload


方式二:

location ~ .php$ {
  root           html;
  #这里尤为注意,可以查看php-fpm的配置是通过127.0.0.1:9000还是通过本地socket文件
  fastcgi_pass   127.0.0.1:9000;
  fastcgi_index  index.php;
  #新版本的nginx默认配置SCRIPT_FILENAME参数在fastcgi_params文件中已定义,所以确保这里定义了即可,如果未定义,可能出现找不到php文件的情况,比如空白页
  fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
  include        fastcgi_params;
}