Nginx subdirectory css and js not wokring Laravel

Am trying to setup multiple laravel projects on nginx server. now in /var/www/htm/ i have two projects demo and demo1

nginx default conf

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    location /demo {

        alias /var/www/html/demo/public;

        try_files $uri $uri/ @nested;

               location ~ \.php$ {
                        include fastcgi_params;
                        fastcgi_param SCRIPT_FILENAME $request_filename;
                        fastcgi_pass   unix:/run/php/php7.4-fpm.sock;


location @nested {
        rewrite /demo/(.*)$ /demo/index.php?/$1 last;

    # pass PHP scripts to FastCGI server
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
    #   # With php-fpm (or other unix sockets):
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    #   # With php-cgi (or other tcp sockets):
    #   fastcgi_pass;

Now here when am trying to access myip/demo then there is no css. i.e <link rel=“stylesheet” href=“/css/demo.css”> this means nginx trying to find css and js files in root directory but files are available in demo directory. how can I solve this? thank you

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.


The problem seems to be that your demo assets are stored at /demo/css/demo.css however you are loading them directly with /css/demo.css. What you could do @asset blade helper.

To do so, in your .env file you need to make sure that you have your ASSET_URL`` set correctly to your_ip/demo:


And then when you load your assets in your blade view, do not specify them directly with <link rel=“stylesheet” href=“/css/demo.css”> but instead use the @asset() helper function:

<link rel=“stylesheet” href=“@asset('css/demo.css')”>

The generated asset URL will be:

For more information, I would recommend taking a look at the official documentation here:

Hope that this helps. Best, Bobby