1

Trying to setup 2 applications with same domain, but different paths. I am running php-fpm with nginx and would need every uri starting with "/sub" to be directed to index.php file of /var/www/sub and all others to be directed to /var/www/main.

Latest test can be found below which resolves my locations (as I see in logs), but in error log I get:

open() "/var/www/sub/test/test" failed (2: No such file or directory)

server {
listen      80;
server_name example.com;

access_log /var/log/nginx/default_access.log;
error_log /var/log/nginx/default_error.log debug;

location / {
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log debug;

    alias /var/main/public;
    index index.php;
    location ~ \.php$ {
        fastcgi_pass  127.0.0.1:9000;
        include       fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;
    }
}

location ^~ /sub {
    access_log /var/log/nginx/sub_access.log;
    error_log /var/log/nginx/sub_error.log debug;

    alias /var/sub/public;
    index index.php;
    location ~ \.php$ {
        fastcgi_pass  127.0.0.1:9000;
        include       fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;
    }
}
}

What might be wrong with this configuration or where should I look next?

EDIT: changed alias paths from /var/main to /var/main/public and /var/sub to /var/sub/public

R.P
  • 500
  • 2
  • 6
  • 17
  • What was the test that resulted in the error? Which error log contained the error message? What was the corresponding entry in the access log? – Richard Smith Aug 29 '19 at 09:11
  • Main: http://example.com/test and http://example.com/test/test -> both resulting in error:[error]: *2 open() "/var/www/main/test/test" failed (2: No such file or directory), server: example.dev, request: "GET /test/test HTTP/1.1", host: "example.dev" Sub: http://example.com/sub/test and http://example.com/sub/test/test resulting in: [error]: *2 open() "/var/www/sub/test/test" failed (2: No such file or directory), server: example.dev, request: "GET /sub/test/test HTTP/1.1", host: "example.dev" – R.P Aug 29 '19 at 09:39
  • The main location should use `root` rather than `alias`. See [this answer](https://stackoverflow.com/questions/42443468/nginx-location-configuration-subfolders/42467562#42467562) for an example of using PHP in a subdirectory with `alias`. – Richard Smith Aug 29 '19 at 13:25

0 Answers0