【问题标题】:Nginx php files are downloading instead of executeNginx php文件正在下载而不是执行
【发布时间】:2019-07-21 13:03:56
【问题描述】:

我在 CentOs 7 上配置了 Ngnix 服务器,它正在使用 html 查找,但是当我尝试打开 .php 文件时,它会被下载。 我正在使用 PHP7.2。 这是我的配置(我使用的是 123.123.123.123 而不是我的真实 ip):

server {
        listen [::]:80 default_server ipv6only=on;
        listen 123.123.123.123:80 default_server;

        root /var/www/example.com/public_html;
        index index.php index.html;

        server_name 123.123.123.123;

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

        location ~ \.php$ {
                try_files $uri /index.php =404;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}

所以当我尝试访问 123.123.123.123/test/index.php 时,我正在下载文件。

如何强制 ngnix 执行 php 文件?

【问题讨论】:

    标签: php nginx centos7 centos6


    【解决方案1】:

    你还需要 fastcgi_pass:

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

    【讨论】:

    • 我应该设置什么ip和端口?
    • 由于PHP-FPM在同一台机器上运行,所以127.0.0.1是正确的。端口默认为 9000。请参阅 /etc/php-fpm.d 中的配置文件
    • 是的,这就是工作。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-17
    • 1970-01-01
    • 2017-06-05
    • 2011-12-30
    • 1970-01-01
    • 2019-08-09
    • 2017-11-16
    相关资源
    最近更新 更多