V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
yehuobumie
V2EX  ›  NGINX

nginx 无法正确解析 php 文件

  •  
  •   yehuobumie · 2016-07-25 10:37:18 +08:00 · 14048 次点击
    这是一个创建于 2832 天前的主题,其中的信息可能已经有所发展或是发生改变。

    1.打开文件后,显示一个可下载的 php 文件,无法看到网页 2.如果打开一个错误的位置,可以显示 nginx 的 404 页面 3.已安装 php 及 php-fpm 4.运行 php 目录中 /bin/php 来解析 php 文件可以成功显示

    6 条回复    2016-07-25 23:55:07 +08:00
    whahuzhihao
        1
    whahuzhihao  
       2016-07-25 11:01:25 +08:00
    指明 fastcgi 与 nginx 交互的地址了吗 比如 php-fpm 的话应该是本地 9000 端口
    fastcgi_pass 127.0.0.1:9000;
    julyclyde
        2
    julyclyde  
       2016-07-25 11:38:56 +08:00
    1 nginx 根本就不解析 php 文件,所以会提供下载
    2
    3 参见楼上
    4 不能说明任何问题
    cndubian
        3
    cndubian  
       2016-07-25 13:07:43 +08:00
    贴个配置文件参考一下,不知道能不能帮到你~~

    server {
    listen 80;
    server_name 192.168.0.128;
    root /var/www/html;
    index index.php index.html index.htm index.nginx-debian.html;

    location / {
    try_files $uri $uri/ =404;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;

    location = /50x.html {
    root /var/www/html;
    }

    location ~ \.php$ {
    try_files $uri =404;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }
    }
    kair
        4
    kair  
       2016-07-25 14:21:59 +08:00
    nginx 不解析 php 文件, php-fpm 才解析,你这种情况是 nginx 运行正常,但是 php 文件没有使用 php-fpm 处理,在 nginx 配置块增加 php 处理模块
    yehuobumie
        5
    yehuobumie  
    OP
       2016-07-25 16:16:20 +08:00
    感谢三楼
    @cndubian
    后来按照
    "fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;"
    重写了 php 部分参数
    然后将
    "root /var/www/html; "
    从 location 中提出到了 server 下就可以正常访问了
    Patrick95
        6
    Patrick95  
       2016-07-25 23:55:07 +08:00
    这种情况就是 nginx.conf
    server 里的 fastcgi 没有配置好。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5447 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 06:54 · PVG 14:54 · LAX 23:54 · JFK 02:54
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.