macbook中搭建nginx+PHP8.3遇到问题,请大神找找原因
按照顺序,成功安装了nginx和PHP8.3
nginx配置文件“nginx.conf”在\opt\homebrew\etc\nginx目录,
PHP配置文件“php-fpm.conf”在\opt\homebrew\etc\PHP\8.3目录。
根据网上的资料,重新对nginx.conf文件中的server下面的location ~ .php$部分进行了修改。如下 所示:
server {
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index 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 html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
location ~ \.php$ {
root /opt/homebrew/var/www/;#因为安装后网站根目录在这个目录下
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
最后,执行nginx和php-fpm命令启动两个服务器都提示成功的。
访问127.0.0.1:8080(或者localhost:8080)能正常打开nginx欢迎页(index.html)。
但不能执行同目录下的index.php文件,而是下载index.php文件。
显然是php没有解析成功。网上也查了很多资料,但都找不到问题所在。
求助CSDN里的大神能帮帮忙。