dongyin5516 2017-03-27 10:55
浏览 85

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

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!

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 教务系统账号被盗号如何追溯设备
    • ¥20 delta降尺度方法,未来数据怎么降尺度
    • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
    • ¥15 再不同版本的系统上,TCP传输速度不一致
    • ¥15 高德地图点聚合中Marker的位置无法实时更新
    • ¥15 DIFY API Endpoint 问题。
    • ¥20 sub地址DHCP问题
    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式