duanmao1919 2018-01-18 22:03
浏览 604
已采纳

NGINX下载PHP文件而不是显示

I'm trying to display index.php and info.php on my NGINX webserver but i cant get it working for some reason, my browser keeps downloading the files instead of displaying them. I tried alot of tutorials but i dont know whats wrong.

OS: Ubuntu 17.10 Server

PHP version: 7.1

cgi.fix_pathinfo is set to 0

www.conf file is default except de cgi.fix_pathinfo

server {
    listen 80 default_server;
    listen [::]:80 default_server;


    root /var/www/html;

  # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.html;

    server_name nginx1.domain.com;

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

    location ~ \.php$ {
            try_files $uri $uri/ =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
    #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    #
    #       # With php5-cgi alone:
            fastcgi_pass 127.0.0.1:9000;
    #       # With php5-fpm:
                fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
    }

    #location ~ /\.ht {
    #       deny all;
    #}
}

Can someone please help me?

  • 写回答

1条回答 默认 最新

  • doukun8944 2018-01-18 22:32
    关注

    Please try this smaller example.

    location ~ \.php$ {
            fastcgi_pass unix:/run/php/php7.1-fpm.sock;
            include snippets/fastcgi-php.conf;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
    

    And double check if your php-fpm is running:

    sudo systemctl status php7.1-fpm.service
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 全志t113i启动qt应用程序提示internal error
  • ¥15 ensp可以看看嘛.
  • ¥80 51单片机C语言代码解决单片机为AT89C52是清翔单片机
  • ¥60 优博讯DT50高通安卓11系统刷完机自动进去fastboot模式
  • ¥15 minist数字识别
  • ¥15 在安装gym库的pygame时遇到问题,不知道如何解决
  • ¥20 uniapp中的webview 使用的是本地的vue页面,在模拟器上显示无法打开
  • ¥15 网上下载的3DMAX模型,不显示贴图怎么办
  • ¥15 关于#stm32#的问题:寻找一块开发版,作为智能化割草机的控制模块和树莓派主板相连,要求:最低可控制 3 个电机(两个驱动电机,1 个割草电机),其次可以与树莓派主板相连电机照片如下:
  • ¥15 潜在扩散模型的Unet特征提取