nginx - 将 PHP 文件作为下载提供,而不是执行它们

标签 nginx php-7 php-7.1

我最近在我的机器上安装了 nginx 和 php 7.0.16,但由于某种原因,nginx 下载了 php 文件,而不是执行它们。我已经花了几天时间并实现了所有在线可用的解决方案,但都是徒劳的。

我的 nginx.conf 是:

worker_processes 4;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.fedora.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

conf.d 文件夹中没有文件,启用站点的只有默认文件,如下所示
server {
    listen 80;
    server_name infrastructure;
    root /home/infra/index;
    index index.php index.html index.htm;
    #return 301 https://$server_name$request_uri;

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

    # pass the PHP scripts to FastCGI server listening on the php-fpm socket
    location ~ \.php$ {
        try_files $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;
        fastcgi_pass unix:/var/run/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    error_page 500 502 503 504 /500.html;
    client_max_body_size 4G;
    keepalive_timeout 10;
}

有人可以请指教,可能是什么问题?

最佳答案

找到了解决办法。问题出在 nginx.conf 文件中。

替换了以下行:

default_type        application/octet-stream;

和:
default_type        text/html;

关于nginx - 将 PHP 文件作为下载提供,而不是执行它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42664080/

相关文章:

PHP array_column() 不返回对象虚假值

php - 为什么在给定浮点范围和间隔时 range() 不包含在内?

regex - Nginx server_name 正则表达式不作为变量工作

linux - nginX - 301 从多个域重定向一个子域

mongodb - 在 PHP7 中使用 "Legacy"MongoDB 驱动程序

symfony - FOS/用户 bundle ProxyManager\配置错误

windows - PHP7.1 + XDebug + WAMP + Visual Studio Code 问题

ruby-on-rails - 我可以将 SPDY 与 Unicorn 一起使用吗?

nginx - 如何使用nginx服务器处理vuejs SPA中的404错误请求

php - 命名空间和扩展类