Nginx配置直接php

Posted Jim

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nginx配置直接php相关的知识,希望对你有一定的参考价值。

nginx配置文件:

server {
    listen       80;
    server_name  localhost;

    access_log  /var/log/nginx/log/host.access.log  main;
    root   /usr/share/nginx/html;  #原本这个设置是在下面localtion里面的

    location / {
        index  index.php index.html index.htm;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location ~* \\.php$ {
        fastcgi_index   index.php;
        fastcgi_pass    127.0.0.1:9000;
        include         fastcgi_params;
        fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;  
        fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
    }
}

php-fpm配置文件(注意:可能有些php版本不是这个文件,但只要意思到位即可):

vi /etc/php-fpm.d/www.conf

修改这两个地方为nginx用户

最后测试php页面:

<?php

phpinfo();

?>

 

 

以上是关于Nginx配置直接php的主要内容,如果未能解决你的问题,请参考以下文章

记一次php nginx配置权限问题

Nginx如何配置实现隐藏php后缀

nginx.conf 忽略了 nginx-ingress 配置映射片段

nginx反向代理配置相对路径

用Nginx如何配置运行无扩展名PHP文件或非.PHP扩展名文件

linux学习:Nginx--常见功能配置片段与优化-06