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 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100