NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
yehuobumie
V2EX  ›  NGINX

nginx 无法正确解析 php 文件

  •  
  •   yehuobumie · Jul 25, 2016 · 15155 views
    This topic created in 3600 days ago, the information mentioned may be changed or developed.

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

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

    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  
       Jul 25, 2016
    nginx 不解析 php 文件, php-fpm 才解析,你这种情况是 nginx 运行正常,但是 php 文件没有使用 php-fpm 处理,在 nginx 配置块增加 php 处理模块
    yehuobumie
        5
    yehuobumie  
    OP
       Jul 25, 2016
    感谢三楼
    @cndubian
    后来按照
    "fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;"
    重写了 php 部分参数
    然后将
    "root /var/www/html; "
    从 location 中提出到了 server 下就可以正常访问了
    Patrick95
        6
    Patrick95  
       Jul 25, 2016
    这种情况就是 nginx.conf
    server 里的 fastcgi 没有配置好。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2784 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 15:33 · PVG 23:33 · LAX 08:33 · JFK 11:33
    ♥ Do have faith in what you're doing.