3

I have installed Magento 2.1.3 , After that I reload the page, css and js are not loading so, I remove the pub/static content. Then regenerate the static content, after that I checked css url path http://hostname/pub/static/version1486463895/frontend/Magento/luma/en_US/mage/calendar.css

But, within the pub/ststic folder there's no version1486463895 folder.

Reference:

enter image description here

I follow link to deploy static content, after the attempt to generate specific theme now also has the same issue.

  bin/magento setup:static-content:deploy  en_US  --theme Magento/luma

Update: My nginx.conf.sample file:

    ## Example configuration:
    # upstream fastcgi_backend {
    #    # use tcp connection
    #    # server  127.0.0.1:9000;
    #    # or socket
    #    server   unix:/var/run/php5-fpm.sock;
    # }
    # server {
    #    listen 80;
    #    server_name mage.dev;
    #    set $MAGE_ROOT /var/www/magento2;
    #    include /vagrant/magento2/nginx.conf.sample;
    # }
    #
    ## Optional override of deployment mode. We recommend you use the
    ## command 'bin/magento deploy:mode:set' to switch modes instead.
    ##
    ## set $MAGE_MODE default; # or production or developer
    ##
    ## If you set MAGE_MODE in server config, you must pass the variable into the
    ## PHP entry point blocks, which are indicated below. You can pass
    ## it in using:
    ##
    ## fastcgi_param  MAGE_MODE $MAGE_MODE;
    ##
    ## In production mode, you should uncomment the 'expires' directive in the /static/ location block

    root $MAGE_ROOT;

    index index.php;
    autoindex off;
    charset UTF-8;
    error_page 404 403 = /errors/404.php;
    #add_header "X-UA-Compatible" "IE=Edge";

    # PHP entry point for setup application
    location ~* ^/setup($|/) {
        root $MAGE_ROOT;
        location ~ ^/setup/index.php {
            fastcgi_pass   fastcgi_backend;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        location ~ ^/setup/(?!pub/). {
            deny all;
        }

        location ~ ^/setup/pub/ {
            add_header X-Frame-Options "SAMEORIGIN";
        }
    }

    # PHP entry point for update application
    location ~* ^/update($|/) {
        root $MAGE_ROOT;

        location ~ ^/update/index.php {
            fastcgi_split_path_info ^(/update/index.php)(/.+)$;
            fastcgi_pass   fastcgi_backend;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO        $fastcgi_path_info;
            include        fastcgi_params;
        }

        # Deny everything but index.php
        location ~ ^/update/(?!pub/). {
            deny all;
        }

        location ~ ^/update/pub/ {
            add_header X-Frame-Options "SAMEORIGIN";
        }
    }

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

    location /pub/ {
        location ~ ^/pub/media/(downloadable|customer|import|theme_customization/.*\.xml) {
            deny all;
        }
        alias $MAGE_ROOT/pub/;
        add_header X-Frame-Options "SAMEORIGIN";
    }

    location /static/ {
        # Uncomment the following line in production mode
        # expires max;

        # Remove signature of the static files that is used to overcome the browser cache
        location ~ ^/static/version {
            rewrite ^/static/(version\d*/)?(.*)$ /static/$2 last;
        }

        location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
            add_header Cache-Control "public";
            add_header X-Frame-Options "SAMEORIGIN";
            expires +1y;

            if (!-f $request_filename) {
                rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
            }
        }
        location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
            add_header Cache-Control "no-store";
            add_header X-Frame-Options "SAMEORIGIN";
            expires    off;

            if (!-f $request_filename) {
               rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
            }
        }
        if (!-f $request_filename) {
            rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
        }
        add_header X-Frame-Options "SAMEORIGIN";
    }

    location /media/ {
        try_files $uri $uri/ /get.php?$args;

        location ~ ^/media/theme_customization/.*\.xml {
            deny all;
        }

        location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
            add_header Cache-Control "public";
            add_header X-Frame-Options "SAMEORIGIN";
            expires +1y;
            try_files $uri $uri/ /get.php?$args;
        }
        location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
            add_header Cache-Control "no-store";
            add_header X-Frame-Options "SAMEORIGIN";
            expires    off;
            try_files $uri $uri/ /get.php?$args;
        }
        add_header X-Frame-Options "SAMEORIGIN";
    }

    location /media/customer/ {
        deny all;
    }

    location /media/downloadable/ {
        deny all;
    }

    location /media/import/ {
        deny all;
    }

    # PHP entry point for main application
    location ~ (index|get|static|report|404|503)\.php$ {
        try_files $uri =404;
        fastcgi_pass   fastcgi_backend;
        fastcgi_buffers 1024 4k;

        fastcgi_read_timeout 600s;
        fastcgi_connect_timeout 600s;

        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    gzip on;
    gzip_disable "msie6";

    gzip_comp_level 6;
    gzip_min_length 1100;
    gzip_buffers 16 8k;
    gzip_proxied any;
    gzip_types
        text/plain
        text/css
        text/js
        text/xml
        text/javascript
        application/javascript
        application/x-javascript
        application/json
        application/xml
        application/xml+rss
        image/svg+xml;
    gzip_vary on;

    # Banned locations (only reached if the earlier PHP entry point regexes don't match)
    location ~* (\.php$|\.htaccess$|\.git) {
        deny all;
    }

After that, I try to remove and deploy the static-content

 rm -rf pub/static/frontend/*
 php bin/magento setup:static-content:deploy

Then I refreash the page:

It shows without css and js:

Reference:

enter image description here

css Path:

enter image description here

I click css url path it goes to a 404 page.

Why does this happen? And how to deploy the static content in Magento 2.1.3?

7
  • which server are you using nginx, apache ?
    – Priyank
    Feb 7, 2017 at 11:06
  • @userpk nginx webserver Feb 7, 2017 at 11:07
  • have you check .htaacess file is there or not in pub/static folder? Feb 7, 2017 at 11:17
  • @Rakesh , i removed .htaccess file in pub/static , its not there Feb 7, 2017 at 11:53
  • you have to keep .htaacess file in pub/static then run command of deploy and remove var folder from root and check. Feb 7, 2017 at 11:57

10 Answers 10

3

Since you are using nginx server you will find nginx.conf.sample in your magento root dir

Use this updated conf file to run your magento source especially this code.

location /static/ {
    # Uncomment the following line in production mode
    # expires max;

    # Remove signature of the static files that is used to overcome the browser cache
    location ~ ^/static/version {
        rewrite ^/static/(version\d*/)?(.*)$ /static/$2 last;
    }

    location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
        add_header Cache-Control "public";
        add_header X-Frame-Options "SAMEORIGIN";
        expires +1y;

        if (!-f $request_filename) {
            rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
        }
    }
    location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
        add_header Cache-Control "no-store";
        add_header X-Frame-Options "SAMEORIGIN";
        expires    off;

        if (!-f $request_filename) {
           rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
        }
    }
3
  • I used nginx.conf.sample in magento root, its looks same has your suugest Feb 7, 2017 at 11:36
  • edit your question and add your nginx conf code
    – Priyank
    Feb 7, 2017 at 12:06
  • I update my nginx.conf.sample file Feb 7, 2017 at 12:09
3

you have to create .htaccess file in pub/static folder with keep below code,

<IfModule mod_php5.c>
php_flag engine 0
</IfModule>

<IfModule mod_php7.c>
php_flag engine 0
</IfModule>

# To avoid situation when web server automatically adds extension to path
Options -MultiViews

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Remove signature of the static files that is used to overcome the browser cache
    RewriteRule ^version.+?/(.+)$ $1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l

    RewriteRule .* ../static.php?resource=$0 [L]
</IfModule>

############################################
## setting MIME types

# JavaScript
AddType application/javascript js jsonp
AddType application/json json

# CSS
AddType text/css css

# Images and icons
AddType image/x-icon ico
AddType image/gif gif
AddType image/png png
AddType image/jpeg jpg
AddType image/jpeg jpeg

# SVG
AddType image/svg+xml svg

# Fonts
AddType application/vnd.ms-fontobject eot
AddType application/x-font-ttf ttf
AddType application/x-font-otf otf
AddType application/x-font-woff woff
AddType application/font-woff2 woff2

# Flash
AddType application/x-shockwave-flash swf

# Archives and exports
AddType application/zip gzip
AddType application/x-gzip gz gzip
AddType application/x-bzip2 bz2
AddType text/csv csv
AddType application/xml xml

<IfModule mod_headers.c>

    <FilesMatch .*\.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$>
        Header append Cache-Control public
    </FilesMatch>

    <FilesMatch .*\.(zip|gz|gzip|bz2|csv|xml)$>
        Header append Cache-Control no-store
    </FilesMatch>

</IfModule>

<IfModule mod_expires.c>

############################################
## Add default Expires header
## http://developer.yahoo.com/performance/rules.html#expires

    ExpiresActive On

    # Data
    <FilesMatch \.(zip|gz|gzip|bz2|csv|xml)$>
        ExpiresDefault "access plus 0 seconds"
    </FilesMatch>
    ExpiresByType text/xml "access plus 0 seconds"
    ExpiresByType text/csv "access plus 0 seconds"
    ExpiresByType application/json "access plus 0 seconds"
    ExpiresByType application/zip "access plus 0 seconds"
    ExpiresByType application/x-gzip "access plus 0 seconds"
    ExpiresByType application/x-bzip2 "access plus 0 seconds"

    # CSS, JavaScript
    <FilesMatch \.(css|js)$>
        ExpiresDefault "access plus 1 year"
    </FilesMatch>
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"

    # Favicon, images, flash
    <FilesMatch \.(ico|gif|png|jpg|jpeg|swf|svg)$>
        ExpiresDefault "access plus 1 year"
    </FilesMatch>
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/jpg "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"

    # Fonts
    <FilesMatch \.(eot|ttf|otf|svg|woff|woff2)$>
        ExpiresDefault "access plus 1 year"
    </FilesMatch>
    ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
    ExpiresByType application/x-font-ttf "access plus 1 year"
    ExpiresByType application/x-font-otf "access plus 1 year"
    ExpiresByType application/x-font-woff "access plus 1 year"
    ExpiresByType application/font-woff2 "access plus 1 year"

</IfModule>

Run command,

php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy

Remove var folder content from root.

5
  • Still same issue. Feb 7, 2017 at 12:22
  • have you create .htaccess file in pub/static and check its available at right location also check using clear broswer cache Feb 7, 2017 at 12:27
  • I checked .htaccess file is there in with in pub/static i cleared magento cache and browser cache, still same issue. Feb 7, 2017 at 12:34
  • i have same version issue exist and keep .htaccess file in pub/static solved my issue. Feb 7, 2017 at 12:35
  • why css url path show pub/static/versionxxxx/frontend//xxx/.css but. its created pub/static/frontend/xxx/xxx/.css right? Feb 7, 2017 at 12:36
3

Remove var/generation, var/cache, var/page_cache directories.

Then Run all the command in sequence:

  1. php bin/magento deploy:mode:set developer (set the mode of environment as developer)
  2. php bin/magento setup:di:compile (generate all the proxies and dependencies )
  3. php bin/magento setup:static-content:deploy (deploy all the static content)
  4. php bin/magento cache:clean; php bin/magento cache:flush (clear the cache)

It will resolve the issue.

1
  • Still same issue Feb 7, 2017 at 11:51
1

take this nginx.conf https://github.com/magento/magento2/blob/develop/nginx.conf.sample#L123

or replace your location /static/ section with the same section in this conf file.

1

Yes, Partiality fixed this issue. nginx.conf.sample file is the issue

I changed root $MAGE_ROOT; root $MAGE_ROOT/pub; it fixed

Working nginx.conf.sample file

        ## Example configuration:
        # upstream fastcgi_backend {
        #    # use tcp connection
        #    # server  127.0.0.1:9000;
        #    # or socket
        #    server   unix:/var/run/php5-fpm.sock;
        # }
        # server {
        #    listen 80;
        #    server_name mage.dev;
        #    set $MAGE_ROOT /var/www/magento2;
        #    include /vagrant/magento2/nginx.conf.sample;
        # }
        #
        ## Optional override of deployment mode. We recommend you use the
        ## command 'bin/magento deploy:mode:set' to switch modes instead.
        ##
        ## set $MAGE_MODE default; # or production or developer
        ##
        ## If you set MAGE_MODE in server config, you must pass the variable into the
        ## PHP entry point blocks, which are indicated below. You can pass
        ## it in using:
        ##
        ## fastcgi_param  MAGE_MODE $MAGE_MODE;
        ##
        ## In production mode, you should uncomment the 'expires' directive in the /static/ location block

        root $MAGE_ROOT/pub;

        index index.php;
        autoindex off;
        charset UTF-8;
        error_page 404 403 = /errors/404.php;
        #add_header "X-UA-Compatible" "IE=Edge";

        # PHP entry point for setup application
        location ~* ^/setup($|/) {
            root $MAGE_ROOT;
            location ~ ^/setup/index.php {
                fastcgi_pass   fastcgi_backend;

                fastcgi_param  PHP_FLAG  "session.auto_start=off \n suhosin.session.cryptua=off";
                fastcgi_param  PHP_VALUE "memory_limit=768M \n max_execution_time=600";
                fastcgi_read_timeout 600s;
                fastcgi_connect_timeout 600s;

                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
            }

            location ~ ^/setup/(?!pub/). {
                deny all;
            }

            location ~ ^/setup/pub/ {
                add_header X-Frame-Options "SAMEORIGIN";
            }
        }

        # PHP entry point for update application
        location ~* ^/update($|/) {
            root $MAGE_ROOT;

            location ~ ^/update/index.php {
                fastcgi_split_path_info ^(/update/index.php)(/.+)$;
                fastcgi_pass   fastcgi_backend;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                fastcgi_param  PATH_INFO        $fastcgi_path_info;
                include        fastcgi_params;
            }

            # Deny everything but index.php
            location ~ ^/update/(?!pub/). {
                deny all;
            }

            location ~ ^/update/pub/ {
                add_header X-Frame-Options "SAMEORIGIN";
            }
        }

        location / {
            try_files $uri $uri/ /index.php$is_args$args;
        }

        location /pub/ {
            location ~ ^/pub/media/(downloadable|customer|import|theme_customization/.*\.xml) {
                deny all;
            }
            alias $MAGE_ROOT/pub/;
            add_header X-Frame-Options "SAMEORIGIN";
        }

        location /static/ {
            # Uncomment the following line in production mode
            # expires max;

            # Remove signature of the static files that is used to overcome the browser cache
            location ~ ^/static/version {
                rewrite ^/static/(version\d*/)?(.*)$ /static/$2 last;
            }

            location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
                add_header Cache-Control "public";
                add_header X-Frame-Options "SAMEORIGIN";
                expires +1y;

                if (!-f $request_filename) {
                    rewrite ^/static/?(.*)$ /static.php?resource=$1 last;
                }
            }
            location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
                add_header Cache-Control "no-store";
                add_header X-Frame-Options "SAMEORIGIN";
                expires    off;

                if (!-f $request_filename) {
                   rewrite ^/static/?(.*)$ /static.php?resource=$1 last;
                }
            }
            if (!-f $request_filename) {
                rewrite ^/static/?(.*)$ /static.php?resource=$1 last;
            }
            add_header X-Frame-Options "SAMEORIGIN";
        }

        location /media/ {
            try_files $uri $uri/ /get.php$is_args$args;

            location ~ ^/media/theme_customization/.*\.xml {
                deny all;
            }

            location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
                add_header Cache-Control "public";
                add_header X-Frame-Options "SAMEORIGIN";
                expires +1y;
                try_files $uri $uri/ /get.php$is_args$args;
            }
            location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
                add_header Cache-Control "no-store";
                add_header X-Frame-Options "SAMEORIGIN";
                expires    off;
                try_files $uri $uri/ /get.php$is_args$args;
            }
            add_header X-Frame-Options "SAMEORIGIN";
        }

        location /media/customer/ {
            deny all;
        }

        location /media/downloadable/ {
            deny all;
        }

        location /media/import/ {
            deny all;
        }

        # PHP entry point for main application
        location ~ (index|get|static|report|404|503)\.php$ {
            try_files $uri =404;
            fastcgi_pass   fastcgi_backend;
            fastcgi_buffers 1024 4k;

            fastcgi_param  PHP_FLAG  "session.auto_start=off \n suhosin.session.cryptua=off";
            fastcgi_param  PHP_VALUE "memory_limit=768M \n max_execution_time=18000";
            fastcgi_read_timeout 600s;
            fastcgi_connect_timeout 600s;

            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        gzip on;
        gzip_disable "msie6";

        gzip_comp_level 6;
        gzip_min_length 1100;
        gzip_buffers 16 8k;
        gzip_proxied any;
        gzip_types
            text/plain
            text/css
            text/js
            text/xml
            text/javascript
            application/javascript
            application/x-javascript
            application/json
            application/xml
            application/xml+rss
            image/svg+xml;
        gzip_vary on;

        # Banned locations (only reached if the earlier PHP entry point regexes don't match)
        location ~* (\.php$|\.htaccess$|\.git) {
            deny all;
        }

now calling same css and js url but, its worked fine.

Why? There are any limitation is there in Magento 2.1.3?

0
0

To deploy static content in magento 2, used following command.

php bin/magento cache:clean
php bin/magento indexer:reindex
php bin/magento setup:upgrade    
php bin/magento setup:static-content:deploy
2
  • I tried this way same issue. Feb 7, 2017 at 10:55
  • I update my answer, try to run this commands. Feb 7, 2017 at 10:57
0

Try with removing Var folder.

rm -rf var/
rm -rf pub/static/frontend/
php bin/magento setup:static-content:deploy

I hope this will help you :)

0

This is due to Magento "Signing" the files. Essentially it forces Magento to regenerate the public static files on page reload by adding the current timestamp to the files.

This may have changed due to an upgrade of version so check the following configuration is set to no:

Store -> Configuration -> Developer -> Static Files Settings -> Sign Static Files

Be sure to flush the caches after this has been changed

0

To deploy content you can run multiple commands at the same time.

rm -rf pub/static/*; rm -rf var/view_preprocessed/*; php -f bin/magento setup:static-content:deploy

0

I've had the same issue changing from developer mode to production and none of the above have worked.

Note: I'm in developer mode before running these commands. Nginx, PHP7.3, Redis, Magento 2.3.4.

This worked for me:

Run the following in your magento/pub/static/ folder. This deletes everything in the static folder except your hidden .htaccess file.

sudo find . -depth -name .htaccess -prune -o -delete

Run the following in your magento root folder

sudo rm -rf var/cache/ var/generation/ var/page_cache/ var/view_preprocessed/ var/composer_home/

sudo php bin/magento deploy:mode:set production

Run the following in your magento root folder (be aware that my user and group is www-data, maybe yours are not)

sudo chown -R www-data:www-data /var/www/magento

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.