Dubby
Dubby

Reputation: 2402

Yii2: /assets/1ecfb338/css/bootstrap.css just loads page, not css

I am having trouble with Yii2 in that it won't load the bootstrap.css file. In fact it's not being created. And when I try to load http://frontend.local/assets/1ecfb338/css/bootstrap.css, it just loads the Yii front page, not the css file.

Why would this happen? Could it be my Nginx config?

server {
set $yii_bootstrap "index.php";
listen    80;

server_name frontend.local;

root /var/www/frontend/web;
index $yii_bootstrap;

access_log  /var/log/nginx/access.log;
error_log   /var/log/nginx/error.log info;


location / {
    try_files $uri $uri/ /$yii_bootstrap?$args;
}

location ~ \.php$ {

    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.(ht|svn|git|sql) {
    deny all;
}

sendfile off;
}

This is running in a Linux VM.

Upvotes: 1

Views: 1051

Answers (2)

ScaisEdge
ScaisEdge

Reputation: 133360

the assest directory are create dinamically when an url request involve the related resoource.

You can try to remove (delete) the content of the directory related th boostrap and see what's happend when you invoce the frontend (or your webApp) url

Be sure your layout contain (for frontend) :

use frontend\assets\AppAsset;


AppAsset::register($this);

and your frontend/assets/AppAsset.php contain reference to bootstrap at least like this (the yii default fro advanced template)

<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace frontend\assets;

use yii\web\AssetBundle;

/**
* @author Qiang Xue <[email protected]>
* @since 2.0
*/
class AppAsset extends AssetBundle
{
  public $basePath = '@webroot';
  public $baseUrl = '@web';
  public $css = [
    'css/site.css',
  ];
  public $js = [
  ];
  public $depends = [
    'yii\web\YiiAsset',
    'yii\bootstrap\BootstrapAsset',
  ];
}

and obviuosly you have a correct yii\bootstrap\BootstrapAssest content

Upvotes: 0

Richard Smith
Richard Smith

Reputation: 49672

The file does not exist. Your try_files directive instructs nginx to serve /$yii_bootstrap whenever the file does not exist, irrespective of file time.

If you add a specific location for static resource files, you will be able to sent an expiry (which is a common strategy) and at the same time, remove them from the file try_files test.

Try adding this to your server block:

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    expires 24h;
#   log_not_found off;
}

Upvotes: 1

Related Questions