centos7部署nginx+php

最近公司新买了一台阿里云的centos7服务器,我要将其配置一下,使用nginx做反向代理,本服务器主要就是放一些php项目。

1、安装nginx:yum install nginx

我将配置文件加在了conf.d文件夹中,新建了一个default.conf作为配置文件,修改nginx.conf文件,将不需要的注释掉

这是default.conf配置文件,我将网站的根目录放在了root文件夹,启动nginx之后访问会出现“403 Forbidden”,此时需要n将nginx.conf中的user nobody改为user root,再次访问即可。

server{
     listen          80 default_server;
     listen          [::]:80 default_server;
     server_name     localhost;
 
     location / {
         root         /root;
         index index.php index.html index.htm;
     }
 
     error_page 404 /404.html;
         location = /40x.html {
     }
 
     error_page 500 502 503 504 /50x.html;
         location = /50x.html {
     }
     location ~ \.php$ {
         try_files $uri =404;
         root /root;
         fastcgi_pass 127.0.0.1:9000;
         fastcgi_index index.php;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         include fastcgi.conf;
      }
}
        

2、安装PHP:请大家参考https://www.cnblogs.com/hello-tl/p/9404655.html

修改/etc/php-fpm.d/www.conf的“user”和“group”

3、我在root文件夹中新建了index.php,访问时候提示“File not found”,原来是需要给root文件夹权限

chmod 777 /root

你可能感兴趣的:(centos,PHP)