lt koi-win mime.types.default nginx.conf.default scgi_params.default uwsgi_params.default
[root@nginx conf]# vim nginx.conf
location / {
root html;
index index.php index.html index.htm ; //添加index.php
}
取消下面的注释并进行修改:
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
修改:
location ~ \.php$ {
root html; //指向php端index.php文件位置
fastcgi_pass 192.168.222.139:9000; //监听php端的9000端口
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/$fastcgi_script_name; // 将/scripts更改为/usr/local/nginx/html
include fastcgi_params;
[root@nginx conf]# cd
[root@nginx ~]# vim /usr/local/nginx/html/index.php //编写php测试页面
[root@nginx ~]# cat /usr/local/nginx/html/index.php
<?php
phpinfo();
?>
[root@nginx nginx]# systemctl restart nginx.service //重启服务
配置php
[root@php ~]# cd /usr/local/php8/etc/php-fpm.d/
[root@php php-fpm.d]# ls
www.conf www.conf.default
[root@php php-fpm.d]# vim www.conf
listen = 192.168.222.139:9000 //php主机ip
listen.allowed_clients = 192.168.222.137 //允许ip访问(nginx主机ip)
[root@php php-fpm.d]# cd
[root@php ~]# cat > /usr/local/nginx/html/index.php << EOF
//编写php端网站
> <?php
> phpinfo();
> ?>
> EOF
[root@php ~]# systemctl restart php-fpm.service //重启服务
[root@php ~]# ss -antl //查看端口
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 192.168.222.139:9000 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
访问:
这里是使用你在刚刚配置里面允许的主机ip进行访问,一般是允许nginx这台主机的ip进行访问