Nginx解析php的配置

Nginx解析php的配置

配置解析php

1.修改虚拟主机配置文件
[root@antong ~]# vim /usr/local/nginx/conf/vhost/test.com.conf  //加入以下内容
   location ~ \.php$
    {
        include fastcgi_params;
        fastcgi_pass unix:/tmp/php-fcgi.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /data/wwwroot/test.com$fastcgi_script_name;
    }
//不进行重启测试

fastcgi_pass 用来指定php-fpm监听的地址或者socket

2.测试
[root@antong ~]# vim /data/wwwroot/test.com/3.php
<?php
phpinfo();
?>
[root@antong ~]# curl -x127.0.0.1:80 test.com/3.php
<?php
phpinfo();
?>
//可以看到没有解析php,我们需要重启一下nginx,再curl一下
[root@antong ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@antong ~]# /usr/local/nginx/sbin/nginx -s reload
[root@antong ~]# curl -x127.0.0.1:80 test.com/3.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<style type="text/css">
body {background-color: #fff; color: #222; font-family: sans-serif;}
pre {margin: 0; font-family: monospace;}
a:link {color: #009; text-decoration: none; background-color: #fff;}
a:hover {text-decoration: underline;}
table {border-collapse: collapse; border: 0; width: 934px; box-shadow: 1px 2px 3px #ccc;}
.center {text-align: center;}
.center table {margin: 1em auto; text-align: left;}
.center th {text-align: center !important;}
···   //解析成功,省略以下。

使用端口来解析

1.修改虚拟主机配置文件
[root@antong ~]# vim /usr/local/php-fpm/etc/php-fpm.conf
[global]
pid = /usr/local/php-fpm/var/run/php-fpm.pid
error_log = /usr/local/php-fpm/var/log/php-fpm.log
[www]
listen = 127.0.0.1:9000
listen.mode = 666    //任何人都可以读sock文件
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
[root@antong ~]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm  done
[root@antong ~]# /usr/local/php-fpm/sbin/php-fpm -t
[06-Sep-2021 08:53:03] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
[root@antong ~]# vim /usr/local/nginx/conf/vhost/test.com.conf  //加入以下内容
   location ~ \.php$
    {
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /data/wwwroot/test.com$fastcgi_script_name;
    }
[root@antong ~]# /usr/local/nginx/sbin/nginx -t                
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@antong ~]# /usr/local/nginx/sbin/nginx -s reload
2.测试
[root@antong ~]# curl -x127.0.0.1:80 test.com/3.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<style type="text/css">
body {background-color: #fff; color: #222; font-family: sans-serif;}
pre {margin: 0; font-family: monospace;}
···   //解析成功,省略以下。
posted @ 2021-09-06 21:07  殇黯瞳  阅读(355)  评论(0编辑  收藏  举报