Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

DcDev's avatar
Level 1

Laravel in subfolder

I have Laravel project in subfolder with NGINX conf:

location  /hotels {
        alias /var/www/user/data/www/site.su/current/hotels/current/public;

        add_header X-Frame-Options "SAMEORIGIN";
        add_header X-Content-Type-Options "nosniff";
     
        index index.php;
     
        charset utf-8;
    
        try_files $uri $uri/ @hotels;
        
     
        location ~ \.php$ {
            fastcgi_pass unix:/var/www/php-fpm/17.sock;
            fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
            include fastcgi_params;
        }
     
        location ~ /\.(?!well-known).* {
            deny all;
        }
    }

With this setup I don't have root path, so links to styles and images shows 404:

/css/app.css -> site.su/css/app.css

but not whata is needed:

/css/app.css -> site.su/hotels/css/app.css

The same with images. I can add prefix /hotels/ to blades, but it has to be nicer way to config it. Because, on my dev env I have this project as root dir. So, it has to work on dev and prod, but how to config it? Without alias in NGINX conf it doesnt work.

0 likes
1 reply
DcDev's avatar
Level 1

Currently I wrapped needed files with asset('/img/img.jpg') and it gibes absolute path, which works in subfolder and in root paths. Any other variants?

Please or to participate in this conversation.