【问题标题】:nginx not opening index.phpnginx 没有打开 index.php
【发布时间】:2019-06-03 21:13:14
【问题描述】:

我正在尝试访问 localhost / other-40.umwelt-campus.de 上的 index.php 文件 但不是调用页面,而是下载一个空文件.. 即使我下载了 php fpm 并进行了配置。

文件位于:/var/www/html/MyDigitalHome/index.php

部分配置文件如下所示:

root /var/www/html/;

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

server_name _;

location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ /index.php$is_args$args;
        # proxy_pass http://localhost:8080;
        # proxy_http_version 1.1;
        # proxy_set_header Upgrade $http_upgrade;
        # proxy_set_header Connection 'upgrade';
        # proxy_set_header Host $host;
        # proxy_cache_bypass $http_upgrade;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
       include snippets/fastcgi-php.conf;

       # With php7.3-cgi alone:
       #fastcgi_pass 127.0.0.1:9000;

       # With php7.3-fpm:
       fastcgi_pass unix:/run/php/php7.3-fpm.sock;

}

php 文件看起来像:

<!-- Redirect to MyDigitalHome mainpage-->
<?php
  header('Location: /MyDigitalHome/src/services/overview.php');
  exit;

【问题讨论】:

  • 查看索引和访问日志。也许您的 PHP 脚本正在生成空内容。您可以使用带有单行 &lt;?php phpinfo(); 的 index.php 文件来测试您的配置。
  • @RichardSmith index.php 正在显示 php 信息。所以它应该工作......
  • 您的 PHP 文件似乎工作正常。
  • @RichardSmith 即使配置了 php.ini,也没有“php_errors.log”。也没有注释掉。那么问题可能是什么?

标签: php nginx fpm


【解决方案1】:

您的重定向已损坏。您必须通过 HTTP 重定向,而是指向本地文件,这意味着它 a) 仅对有权访问该文件系统的人(通常只有您)可用,b) 由 Web 浏览器直接访问 所以无论你的 nginx 配置有多好,这都无关紧要,因为服务器不参与文件访问(它甚至可以关闭,如果你有文件系统访问权限,你将获得该文件)。

【讨论】:

  • 我该怎么做?只需添加“other-40.umwelt-campus.de/MyDigitalHome/src/services/…”?
  • 你不能添加一些随机字符并期望它工作。该文件必须可用于 Web 服务器,因此在配置的文档根目录中。
  • 所以你必须把那个文件,即在当前提供的文件旁边(比如复制到/var/www/html/MyDigitalHome/,然后重定向到overview.php(或者services/overview.php,如果你想复制整个树)
  • 该文件位于 /src/services/overview.php 。所以我想那是正确的道路。
猜你喜欢
  • 2017-07-27
  • 2011-01-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-10
相关资源
最近更新 更多