1

i am having trouble to load images that saved in default images directory laravel (laravelroot/public/images). i've set the laravel on http://domain/laravelroot. here is the configurations :

server {
    listen 80;
    server_name localhost;
    index index.php;
    root /usr/share/nginx/html;

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

location ~ /.well-known {
            allow all;
    }

location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
    access_log        off;
    log_not_found     off;
    expires           360d;
    }

location ^~ /laravelroot {  
            alias /usr/share/nginx/html/laravelroot/public;  
            try_files $uri $uri/ @laravelroot;  

            location ~ \.php {  
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.1-fpm.sock; 
                fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/laravelroot/public/index.php;
                }  
        }  

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

on element inspect , its domain refer to http://localhost/imagefile. when i open the images on the new tab, and change the url to http://localhost/laravelroot/images/imagefile.png its loaded.

I've tried to put images location in laravelroot directives.

location ^~ /laravelroot {  
                alias /usr/share/nginx/html/laravelroot/public;  
                try_files $uri $uri/ @laravelroot;  

            location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
                  alias /usr/share/nginx/html/laravelroot/public/images;
                  access_log        off;
                  log_not_found     off;
                  expires           360d;
                  }

            location ~ \.php {  
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.1-fpm.sock; 
                fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/laravelroot/public/index.php;
                }  
        }  

and didnt work. spent few hours but no clue today

1 Answers1

1

i found the problem. the laravel itself need to set the base path for images.

i put all assets in the public folder, then use the HTML::image() Method, and only needs an argument which is the path to the image, relative on the public folder, as well:

{{ HTML::image('images/picture.png') }} Which generates the follow HTML code:

http://localhost/images/picture.png

seems a bit too far from serverfault. but thanks anyway.