magento2: Magento 2 Installation: css/js/images not loading in php-fpm + nginx server

I am trying to install Magento2(0.1.0-alpha107 ) in my localhost powered by OSX 10.10 + brew installed php-fpm + mysql + nginx. Steps that I followed for installation:

 $ mkdir /path/to/magento2 && cd /path/to/magento2
 $ git clone git@github.com:magento/magento2.git .
 $ composer install
 $ cd setup
 $ composer install
 $ php -f index.php install --base_url=http://magento2alpha.dev/ --backend_frontname=admin --db_host=localhost --db_name=magento2alpha --db_user=root --db_pass=root --admin_firstname=Raj --admin_lastname=KB --admin_email=magepsycho@gmail.com --admin_username=admin --admin_password=pass123 --language=en_US --currency=USD --timezone=America/Chicago

So far everything worked great. But when you load the frontend: http://magento2alpha.dev/ it’s showing plain text only (i.e. css/images/js are missing).

View source gives you the path like http://magento2alpha.dev/pub/static/frontend/Magento/blank/en_US/[css/images]/[css/images file] which led to the 404 page My nginx conf file looks like:

server {
    listen 80;
    server_name magento2alpha.dev;
    root /Users/Raj/Sites/magento/magento2alpha;

    location /setup {
        try_files $uri $uri/ @setuphandler;
    }

    # Rewrite Setup's Internal Requests
    location @setuphandler {
        rewrite /setup /magento/magento2alpha/setup/index.php;
    }

    location / {
        index index.php index.html;
        try_files $uri $uri/ @handler;
    }

     # Rewrite Internal Requests
     location @handler {
        rewrite / /magento/magento2alpha/index.php;
     }

     # Rewrite magento2 static files
     #location /pub/static {
     #   rewrite ^/pub/static/(.*)$ /magento/magento2alpha/pub/static.php?resource=$1? last;
     #}

     location /pub/static {
          try_files $uri $uri/ @static;
     }

     location @static {
           rewrite ^/pub/static/(.*)$ /magento/magento2alpha/pub/static.php?resource=$1? last;
     }

     #location ~ .php/ {
     #    rewrite ^(.*.php)/ $1 last;
     #}

    location ~ \.php$ { ## Execute PHP scripts
        try_files $uri =404;
        expires        off;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_read_timeout 900s;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;

        ## Magento 2 Developer mode
        fastcgi_param MAGE_MODE "developer";
    }
}

I guess the issue lies in the static files rewrite. But this is what I followed from the github which is not working. Is there any workaround?

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 23 (20 by maintainers)

Commits related to this issue

Most upvoted comments

I use this config

index index.php;
root  /Users/Raj/Sites/magento/magento2alpha;

autoindex off;
# disable_symlinks on;
charset off;
#charset utf-8;
location /setup {
    try_files $uri $uri/ @setup;
}

location @setup {
    rewrite /setup /setup/index.php;
}

location / {
    rewrite / /index.php ;
}

location /pub/static {
    try_files $uri @static;
}

location @static {
    rewrite ^/pub/static/(version\d*/)?(.*)$ /pub/static.php?resource=$2 last;
}

location /pub/media {
    try_files $uri/ @mediahandler;
}
location @mediahandler {
    rewrite / /get.php;
}

location /pub/media/customer {
    deny all;
}
location /pub/media/downloadable {
    deny all;
}
location ~ /pub/media/theme_customization/.*\.xml$ {
    deny all;
}
location ~ /pub/errors/.*\.(xml|phtml)$ {
    deny all;
}

location ~ \.php$ {
    #fastcgi_pass   127.0.0.1:9000;
    fastcgi_pass   unix:/var/run/php5-fpm.sock;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_param  PHP_FLAG  "session.auto_start=off \n suhosin.session.cryptua=off";
    fastcgi_param  PHP_VALUE "memory_limit=256M \n max_execution_time=18000";
    fastcgi_param  MAGE_MODE "developer";
    include        fastcgi_params;
}

and static files works as expected