首页 > 技术文章 > LNMP配置——Nginx配置 —— Nginx解析PHP

lsy579 2021-03-10 16:20 原文

一、配置

#vi /usr/local/nginx/conf/vhost/test.com.conf

写入:

server

{

    listen 80;

    server_name test.com test1.com test2.com;

    index index.html index.htm index.php;

    root /data/nginx/test.com;

    if ($host != 'test.com' ) {

        rewrite ^/(.*)$ http://test.com/$1 permanent;

    }

    location ~ \.php$

    {

    include fastcgi_params;

    fastcgi_pass unix:/tmp/php-fcgi.sock;

    fastcgi_index index.php;

    fastcgi_param SCRIPT_FILENAME /data/nginx/test.com$fastcgi_script_name;

    }

   access_log /tmp/1.log combined_realip;

}

//fastcgi_pass用来指定php-fpm的地址

 

# vim /data/nginx/test.com/3.php

写入:

<?php

phpinfo();

?>

 

# curl -x

curl -x192.168.244.128:80 test.com/3.php

test.com/3.php

写入:

<?php

phpinfo();

?>

 

 

重新加载nginx

# /usr/local/nginx/sbin/nginx -t

 

 

# /usr/local/nginx/sbin/nginx -s reload

# curl -x192.168.244.128:80 test.com/3.php

 

推荐阅读