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难题
    • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
    • ¥15 牛顿斯科特系数表表示
    • ¥15 arduino 步进电机
    • ¥20 程序进入HardFault_Handler
    • ¥15 oracle集群安装出bug
    • ¥15 关于#python#的问题:自动化测试
    • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
    • ¥15 教务系统账号被盗号如何追溯设备
    • ¥20 delta降尺度方法,未来数据怎么降尺度