首页 > 编程 > PHP > 正文

nginx不解析php代码;解决方法

2019-11-08 01:16:15
字体:
来源:转载
供稿:网友
安装:sudo apt-get install nginx php7.0-fpm MySQL-server-5.6 php7.0-mysql然后改配置文件,php的配置文件不用改就能用,nginx的配置文件不行,默认情况下是不支持php CGI的,所以得改一下:vim /etc/nginx/sites-available/default找到##location ~ /.php$ {# include snippets/fastcgi-php.conf;## # With php5-cgi alone:# fastcgi_pass 127.0.0.1:9000;# # With php5-fpm:# fastcgi_pass unix:/var/run/php5-fpm.sock;#}改成location ~ /.php$ {include snippets/fastcgi-php.conf;# With php5-cgi alone:#fastcgi_pass 127.0.0.1:9000;# With php5-fpm:fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;}大概意思就是所有以 .php 积极结尾的文件都传给php7.0-fpm去处理,处理完了把结果发给nginx,然后再由nginx发给客户机然后重启一下服务:systemctl restart nginxsystemctl restart php7.0-fpmsystemctl restart mysql就好啦默认的网站根目录在/var/www/html/(可以通过nginx的配置文件里root 的那行改)题主要是想搭WordPRess之类的话,要把index.php当做主页的就是把nginx配置文件中的index index.html index.htm index.nginx-debian.html;改成 index.php
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表