centos7环境
1.14.2版本
安装:
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum -y install nginx
安装完成
启动Nginx
systemctl start nginx.service
访问ip
配置Nginx支持php
编辑配置文件 default.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
access_log /var/log/nginx/host.access.log; # 日志路径
error_log /var/log/nginx/error.log; # 日志路径
location / {
root /opt/www; #这里是根目录
index index.php index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#把这里的注释放开,注意fastcgi_param参数的修改
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
配置编辑完成之后,重新启动nginx,可以使用以下命令重启:
systemctl restart nginx.service
也可以重新加载配置文件,也叫热启动:
nginx -s reload
然后在根目录下创建一个php文件,打印php信息
输入IP或者自己的域名访问
配置成功