CentOS 6.3安装配置nginx+php+mysql

2019-10-13 21:28:17王冬梅

配置篇

 nginx的配置文件是/etc/nginx下的nginx.conf。在nginx.conf文件的最后一行可以看到: include /etc/nginx/conf.d/*.conf; 它把 /etc/nginx/conf.d目录下后缀为.conf的文件都包含进来了,所以只要在/etc/nginx/conf.d/这个目录下配置一个.conf文件就行了。以下是我的配置:

#
# The default server
#

server {
  listen    80;
  server_name n.com;
  root     /usr/share/nginx/html;
  index index.php index.html;

  # Load configuration files for the default server block.

  location / {
  try_files $uri $uri/ /index.php?$args;
  }

  location ~ .*.(php)?$ {
    expires -1s;
    try_files $uri =404;
    fastcgi_split_path_info ^(.+.php)(/.+)$;
    include fastcgi_params;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass 127.0.0.1:9000;
  }
  error_page 404 /404.html;
    location = /40x.html {
  }

  error_page 500 502 503 504 /50x.html;
    location = /50x.html {
  }

}

  重启nginx:

service nginx restart

在/usr/share/nginx/html/这个目录下新建一个index.php

cd /usr/share/nginx/html  #进入html目录
vim index.php        #新建index.php,加上phpinfo();

浏览器访问:centos的ip地址/index.php。完成!