nginx php7只能在文档根目录下工作

在这里初学者;)</ p>

我将一个页面从一个VPS移动到另一个VPS 安装nginx,php7等后(使用本教程)一切都运行良好。
添加SSL完全没问题。</ p>

但是如果我执行任何php文件( 在任何新创建的子文件夹fe mydomain.pw/newfolder/index.php我得到一个空白的结果。
如果我在页面根文件夹(WP)中执行相同的文件,它可以正常工作。</ p> \ n

我已将我的用户添加到www-data组并提供了与之前VPS相同的权限。
如果我检查nginx错误日志或php7.0-fpm.log我没有收到错误 完全没有。</ p>

如果有人有任何提示或想法是什么问题,我真的很感激。

我怀疑是一个权限错误但在SO和Google上搜索没有成功。</ p>

这是我的nginx conf:</ p>

  server {
listen [::]:80 default_server ipv6only = on;
listen 80 default_server;
#listen on the www and non-www host
server_name www.mydomain.pw mydomain.pw;

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

#并重定向到https主机(在下面声明)

返回301 https://mydomain.pw$request_uri;

位置〜\ .php $ {

try_files $ uri $ uri / /index.php?$args;
nn fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; \ n
fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;

包括fastcgi_params;
}
}

{
listen [::]:443 ssl;

listen 443 ssl;

server_name www.mydomain.pw mydomain.pw;

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

ssl_certificate / etc / letsencrypt /现场/平方米 ydomain.pw/fullchain.pem;
nn ssl_certificate_key /etc/letsencrypt/live/mydomain.pw/privkey.pem;
nn location~ \ .php $ {

try_files $ uri $ uri / / index.php?$ args;

fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name; \ n
包括fastcgi_params;

}

位置〜* \。(jpg | jpeg | png | gif | ico | css | js)$ {
expires 365d;
}
}
</ code> </ pre>

提前致谢!</ p>
</ div>

展开原文

原文

beginner here ;)

I moved a page from one VPS to another and after installing nginx,php7 etc (using this tutorial) everything is working great. Added SSL no problem at all.

However if I execute any php files (f.e hello world) in any newly created subfolder f.e mydomain.pw/newfolder/index.php I get a blank result. If I execute the same file in the page root folder (WP), it works fine.

I have added my user to the www-data group and gave the same permission as I did on the former VPS. If I check the nginx error log or php7.0-fpm.log I get no error at all.

If anyone has any hint or idea what the problem is, I'd really appreciate it. I suspect a permission error but searched on SO and Google without success.

Here is my nginx conf :

server {
  listen [::]:80 default_server ipv6only=on;
  listen 80 default_server;
  # listen on the www and non-www host
  server_name www.mydomain.pw mydomain.pw;

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

  # and redirect to the https host (declared below)

  return 301 https://mydomain.pw$request_uri;

  location ~ \.php$ {

            try_files $uri $uri/ /index.php?$args;

            fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;

            fastcgi_index index.php;

            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

            include fastcgi_params;
    }
}
server {
  listen [::]:443 ssl;

  listen 443 ssl;

  server_name www.mydomain.pw mydomain.pw;

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

  ssl_certificate /etc/letsencrypt/live/mydomain.pw/fullchain.pem;

  ssl_certificate_key /etc/letsencrypt/live/mydomain.pw/privkey.pem;

  location ~ \.php$ {

            try_files $uri $uri/ /index.php?$args;

            fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;

            fastcgi_index index.php;

            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

            include fastcgi_params;

      }

  location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
    expires 365d;
  }
  }

Thanks in advance!

dongyi3776
dongyi3776 error_log$document_root/info_log.txtinfo;
3 年多之前 回复
dsc6517
dsc6517 结帐你nginx访问日志和错误日志
3 年多之前 回复
dsfsda121545
dsfsda121545 首先检查服务器的错误日志......
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐