簡體   English   中英

Niginx下載PHP文件而不是執行index.php

[英]Niginx Downloads PHP files Instead of Executing index.php

Nginx下載php文件而不是執行

具有PHP 7.0的Ubuntu 16.04 Nginx。

Nginx版本:Nginx / 1.10.3(Ubuntu)

我必須執行的文件位於/var/lib/customdir/customfiles/index.php

這是我的默認配置文件。 出於安全原因,我刪除了目錄的實際名稱。

 # Default server configuration
 #
 server {
     listen 80 default_server;
     listen [::]:80 default_server;

    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #
    # Note: You should disable gzip for SSL traffic.
    # See: https://bugs.debian.org/773332
    #
    # Read up on ssl_ciphers to ensure a secure configuration.
    # See: https://bugs.debian.org/765782


         root /var/lib/customdir/customfiles/index.php

    # root /var/www/html;

    # root /usr/share/nginx/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 54.252.213.xxx;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

  location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:var/run/php/php7.0-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }

我嘗試了上述方法的許多不同變體,但均未成功。

任何幫助將不勝感激。

嘗試這個:

root /var/lib/customdir/customfiles/
location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}

在這里,我更新了root (指向不是文件的根目錄)和fastcgi_pass (指向絕對dir /var而不是相對目錄)。

1)根目錄應該是root /var/lib/customdir/customfiles (無文件index.php)。

2)檢查/etc/php7.0/fpm/php.ini cgi.fix_pathinfo值(或/etc/php/7.0/fpm/php.ini )? 需要將其設置為0

3)將您的location ~ \\.php$指令修改為:

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; #you have a missing / before var
    fastcgi_split_path_info ^(.+\.php)(/.+)$; #add this line
}

使用以下命令測試配置:

sudo nginx -t

在重新加載nginx配置之前,查看是否有任何錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM