0

We have an issue with calling php files in subdirectories of domain.

What's working without an issue:

example.com/mod/eco/file.php

but when our domain is placed with a virtual subdirectory it's not working like this:

example.com/b2b-dk/mod/eco/file.php

Here is the nginx conf:

server {
    listen 80;
    listen [::]:80;
    server_name .example.com;
    root /home/forge/example.com;

    index index.html index.htm index.php;

    charset utf-8;

    location / {
      index /index.php;

      rewrite ^/admin462twqbah/?$ /admin462twqbah/index.php permanent;
      rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;
      rewrite ^/([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$1$2.jpg last;
      rewrite ^/([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$1$2$3.jpg last;
      rewrite ^/([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$1$2$3$4.jpg last;
      rewrite ^/([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$1$2$3$4$5.jpg last;
      rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6.jpg last;
      rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7.jpg last;
      rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8.jpg last;
      rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9.jpg last;
      rewrite ^/c/([0-9]+)(-[_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2.jpg last;
      rewrite ^/c/([a-zA-Z-]+)(-[0-9]+)?/.+\.jpg$ /img/c/$1.jpg last;
      rewrite ^/([0-9]+)(-[_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2.jpg last;
      try_files $uri $uri/ /index.php?$args;
    }

    location /b2b-dk/ {
      rewrite ^/b2b-dk/(.*)$ /$1 last;
      try_files $uri $uri/ /index.php?$args;
    }

    location /b2b-eu/ {
      rewrite ^/b2b-eu/(.*)$ /$1 last;
      try_files $uri $uri/ /index.php?$args;
    }

    location /b2b-us/ {
      rewrite ^/b2b-us/(.*)$ /$1 last;
      try_files $uri $uri/ /index.php?$args;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/example.com-error.log error;

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /b2b-dk/.+\.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

So I tried to get this part to work:

location ~ /b2b-dk/.+\.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
            include fastcgi_params;
        }

But not with any luck - what am I doing wrong?

7
  • Does nginx error.log contain any information? Oct 30 '16 at 21:36
  • 2016/10/30 22:43:31 [error] 8948#8948: *71 FastCGI sent in stderr: "Unable to open primary script: /home/forge/example.com/b2b-dk/mod/eco/file.php (No such file or directory)" $ Oct 30 '16 at 21:45
  • And what is the exact path of your application on the server? Oct 30 '16 at 21:58
  • /home/forge/example.com - IF YOU MEAN SITE FILES. Oct 30 '16 at 21:59
  • Sorry, I meant the path to the file.php mentioned in error.log. Oct 30 '16 at 22:00
0

This was solved by changing the location block for forum PHP files like this:

location ~ /b2b-dk/.+\.php$ {
    rewrite ^/b2b-dk/(.*)$ /$1 last;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
    include fastcgi_params;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.