P
P
part_os2020-10-04 14:48:36
Nginx
part_os, 2020-10-04 14:48:36

Can't change root in nginx, why?

Hello everyone, I'm trying to set up nginx to share an application:
there are 2 directories with applications:
/var/www/neel/appRlLara/public;
/var/www/neel/appRlLara/legacy;

I want the URL:
neel_rl.neel/ used on /var/www/neel/appRlLara/legacy;
and for all routes neel_rl.neel/appRlLara used in /var/www/neel/appRlLara/public;

tried like this:

server {
    server_name neel_rl.neel;

    location /appRlLara {
        root /var/www/neel;
        try_files $uri /appRlLara/public/index.php$is_args$args;
    }

    location / {
        root /var/www/neel/appRlLara/legacy;
    }

    index index.html index.htm index.php;

     location ~ \.php$ {
         fastcgi_pass rl.php54:9000;
         fastcgi_index  index.php;
         fastcgi_param  SCRIPT_FILENAME  $realpath_root$fastcgi_script_name;
         include        fastcgi_params;
     }

    error_log /var/log/nginx/neel_error.log;
    access_log /var/log/nginx/neel_access.log;
}


now the working configuration is like this, but the legacy code is right at the root /var/www/neel;
server {
    server_name neel_rl.neel;
    root /var/www/neel;

    location /appRlLara {
        try_files $uri /appRlLara/public/index.php$is_args$args;
    }

    index index.html index.htm index.php;

    client_max_body_size 50m;

     location ~ \.php$ {
         fastcgi_pass rl.php54:9000;
         fastcgi_index  index.php;
         fastcgi_param  SCRIPT_FILENAME  $realpath_root$fastcgi_script_name;
         include        fastcgi_params;
     }

    error_log /var/log/nginx/neel_error.log;
    access_log /var/log/nginx/neel_access.log;
}


and if you simply call the domain neel_rl.neel/, the server gives you to download the index.php file which lies in /var/www/neel/appRlLara/public;
how to set it up to work?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2020-10-04
@part_os

server {
    server_name neel_rl.neel;

    root /var/www/neel/appRlLara/legacy;

    location / {
        try_files $uri /index.php$is_args$args;

        location ~ \.php$ {
            fastcgi_pass rl.php54:9000;
            fastcgi_param  SCRIPT_FILENAME  $realpath_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
    
    location /appRlLara {
        root /var/www/neel/appRlLara/public;

        rewrite ^/appRlLara/(.*) /$1 break;

        try_files $uri /appRlLara/index.php$is_args$args;

        location ~ \.php$ {
            rewrite ^/appRlLara/(.*) /$1 break;

            fastcgi_pass rl.php54:9000;
            fastcgi_param  SCRIPT_FILENAME  $realpath_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question