Magento 2設置:CSS / JS /画像がロードされていない
-
12-12-2019 - |
質問
OSX 10.10 + BREWが搭載したPHP-FPM + MySQL + Nginxを搭載したMy LocalhostにMagento2(0.1.0-alpha107)をインストールしようとしています。 インストールのための手順:
-
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
これまでのところすべてがうまくいった。しかし、フロントエンドをロードするとき: http://magento2alpha.dev/ プレーンテキストのみを表示しています(すなわち、CSS / Images / JSが見つかりません)。
ソースを表示する HTTP ://magento2alpha.dev/pub/static/frontend/magento / blank/en_us/ [CSS / ImageS] / [CSS / Images ファイル] 404ページにつながった
My Nginx Confファイルは次のようになります。
.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"; } }
私は問題が静的ファイルの書き換えにあると思います。しかし、これは私が働いていないgithubから従ったものです。 回避策はありますか?
解決 2
最後に、私はそれを働くために私のNginx Confファイルを変更しなければなりません:
(Ref: https://github.com/magento/magento2/issues/802 )
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 /setup/index.php;
}
location / {
index index.php index.html;
try_files $uri $uri/ @handler;
}
# Rewrite Internal Requests
location @handler {
rewrite / /index.php;
}
location /pub/static {
try_files $uri $uri/ @static;
}
location @static {
rewrite ^/pub/static/(.*)$ /pub/static.php?resource=$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";
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";
}
}
.
気づいたことの1つは、NGINXのconf.d
で仮想ホスト固有の設定を作成すると、sites-enabled
Dirに保存するよりも費用が高く遅くなります。
[編集]
すみません、私の悪い、XdebugはNginxのconfではなく遅いものを引き起こしていました。
他のヒント
現在存在しない/pub/static
内で要求されているファイルは、現在Magentoを介してルーティングされる必要があります。これは現在/pub/static.php
を介して行われています。
/pub/static/.htaccess
でこの書き換えを見ることができます
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]
.
あなたのNGINX構成を見るあなたはこれをコメントアウトしています:
# Rewrite magento2 static files
#location /pub/static {
# rewrite ^/pub/static/(.*)$ /magento/magento2alpha/pub/static.php?resource=$1? last;
#}
.
これらの線を実行可能なものにすることは問題を解決するだろう、私はNginxの設定にはあまり精通していませんが、このようなものはも機能します:
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /../static.php?resource=$0 last;
}
}
. から: https://magento.stackexchange.com/a/64808/3326
本番モードではない場合Magento 2は、静的リソースのシンボリックリンクを作成しようとします。次のようにすることで、その動作を変更できます。
app/etc/di.xml
を開き、virtualType name="developerMaterialization"
セクションを見つけます。そのセクションでは、変更または削除する必要があるアイテムname="view_preprocessed"
があります。Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink
からMagento\Framework\App\View\Asset\MaterializationStrategy\Copy
の内容を変更することで変更できます。
pub/static
の下のファイルを削除して、既存のシンボリックリンクを取り除きます。.htaccess
ファイルを削除しないように注意してください。
これはシンボリックリンクであなたのエラーを解決するべきです。
これはこれまでのところ最良の答えです
コンテンツを変更することで変更できます。
Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink
ToMagento\Framework\App\View\Asset\MaterializationStrategy\Copy
Magento 2のインストールを実行した後にも同様の問題があり、インストールが実際に静的ファイルをデプロイできなかったことがわかりました。Static File Deploymentを強制するためにサイトルートからコマンドを実行するために、BootStrapなどを含む多くの管理ファイルの場合は404を受け取りました。
php bin/magento setup:static-content:deploy -f
.
これはフロントエンドテーマとAdminHTMLバックエンドの静的資産を再指示します。