nginx local redirect from /var/www/html/index.html to /var/www/html/larvel_project/public

1.2k Views Asked by At

we are working on a local WIFI project where we use internet-enabled Ubuntu server inside CPU and we don't have any domain name to point it. We provide wifi access from the CPU server so that anyone can access it within our local premises.

For captive portal working, we need to have generate_204 folder inside the following

/var/www/html/generate_204/

from here we redirect to index.php which is at the same level of generate_204 folder as following

/var/www/html/index.php

from here I want to redirect to my Laravel project folder which resides inside the same level as following

/var/www/html/laravel_project/public/

The overall structure is as follows

/var/www/html/
            index.php
            generate_204/
                        index.php
            laravel_project/
                           public/
                                 index.php

How can I achieve redirection from /var/www/html/index.php to /var/www/html/laravel_project/public/

Following is my current NGINX setup:

server {
    listen 80 default_server;
        root /var/www/html;
        index index.php index.html;
    server_name _;
    add_header Access-Control-Allow-Origin *;
        location / {
        try_files $uri $uri/ =404;
        }

        location ~ \.php$ {
        include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }


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

The above NGINX setup works fine when we had a plain PHP project and we were redirecting.

Any help really appreciated.

1

There are 1 best solutions below

1
On

I dont think there is a need to redirect to your laravel folder. Just change the line root /var/www/html; to root /var/www/html/laravel_project/public;

also i have

location / {
    try_files $uri $uri/ /index.php?$query_string;
}