【问题标题】:nginx isn't parsing php in nextcloud installnginx 没有在 nextcloud 安装中解析 php
【发布时间】:2018-04-30 02:20:11
【问题描述】:

我正在尝试在树莓派 3(树莓派)上设置 nextcloud 服务器。

我在使用 nginx 和 mysql 构建堆栈方面总体上是成功的。但是,我遇到了一个nginx不解析php的问题。

也就是说,当我导航到 pi 的 nextcloud 安装时,浏览器提示我打开/保存 index.php(下一个云登录屏幕),这告诉我服务器根本没有解析它。我找到了一个指向 nextcloud 文档的链接,该链接建议添加:

index index.html index.htm index.php

到 nginx.conf 文件。不幸的是,它似乎没有效果。

关于如何解决此问题或尝试其他想法的任何提示?

编辑:基于 cmets 和第一个答案,我已经更新了我的 /etc/nginx

编辑#2:恢复到默认的 nginx.conf 文件,并在下面的 /etc/nginx/sites-enabled/default 的答案中添加了@Mason Stedman 的代码。此外,使用以下教程(通过第 7 步)在重新闪烁 raspian 拉伸后设置堆栈:

https://linoxide.com/debian/install-nextcloud-10-nginx-debian-8/

为了完整起见,我的 /etc/nginx/sites-enabled/default 文件如下。对于服务器名称,我不知道要输入什么,所以我使用了我在网络上分配给它的静态 IP 地址(顺便说一句,我没有将它暴露给互联网):

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

       server_name 192.168.xx.xx;

       access_log /var/log/nginx/access.log;
       error_log /var/log/nginx/error.log;

       root /var/www/;
       index index.php index.html;

       location / {
            try_files \$uri \$uri/ /index.php?\$query_string;
       }

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

}

【问题讨论】:

标签: php nginx


【解决方案1】:

尝试将其添加到您的 nginx 配置中:

编辑:这是您需要放入其中才能工作的全部内容的示例。如果您需要 SSH 支持或更全面的示例,我可以再次编辑,但此示例几乎适用于任何配置。

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

       server_name site.com www.site.com;

       access_log /var/log/nginx/site.com.access.log;
       error_log /var/log/nginx/site.com.error.log;

       root /var/www/site.com/htdocs/;
       index index.php index.html;

       location / {
            try_files \$uri \$uri/ /index.php?\$query_string;
       }

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

}

您需要将 php 文件发送到解析器。您可以将其中的版本更改为您要使用的php版本。

【讨论】:

  • 好的,这就是我所做的: 1. 将@Tan Hon Tat(上)建议的 nextcloud nginx 配置添加到默认的 /etc/nginx/nginx.conf 文件中。 nextcloud 配置已插入 http { } 标头部分 2。将上面建议的位置添加到先前插入的 nextcloud 配置中。注意我注释掉了默认的“location / {}”声明,因为它有冲突。有关详细信息,请参阅对我的原始帖子的编辑
  • 更新了一个完整的例子
  • 恐怕还是没有运气。我做了更多的谷歌搜索,并注意到一个示例将所有服务器块内容推送到 /etc/nginx/conf.d/nextcloud.conf。不知道这是否重要。我还注意到 nextcloud 可能需要一个 config.php 文件?我看到在 nextcloud 树中有一个 config.sample.php 文件,但不确定 config.php 会去哪里。不过,我确实找到了一两个关于应该包含什么的建议......
  • 我发布的示例与使用通用 nginx 配置一样简单,您是否应该在系统上安装 php 等?发布您遇到的错误可能会有所帮助。
  • 刷新了我的卡并从头开始。按照教程并设置 /etc/nginx/sites-enabled 如上所示。现在它要求我创建一个管理员用户和数据库,告诉我安装了 MariaDB,但无论如何它都会使用 SQLite。无法连接到数据库...但访问日志清楚地显示我正在运行 nextcloud... 进度,我猜。