0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Dockerコンテナ内でCSSが反映されない

Posted at

前提

  • PHP 8.2.10
  • Laravel8
  • Docker環境下で動作

事象

Dockerコンテナ外では CSS がブラウザに反映されている

$ php artisan serve

$ npm run dev

スクリーンショット 2024-09-22 22.47.19.png

ただ Docker コンテナ内になると CSS がブラウザに反映されなくなる

$ docker-compose up -d
[+] Running 4/4
 ✔ Container laravelapp-mysql-1  Started
 ✔ Container laravelapp-node-1   Started
 ✔ Container laravelapp-php-1    Started
 ✔ Container laravelapp-nginx-1  Started


 $ docker-compose exec node npm run dev

スクリーンショット 2024-09-22 22.51.10.png

原因

Nginx に MIMEタイプを設定していなかったため
コンパイルによって CSS ファイルは作成されていたが、正しく CSS を読み込めていなかった

解消法

nginx.conf の http に include /etc/nginx/mime.types; を追記

...
http {
    include /etc/nginx/mime.types;

    server {
        listen 8000;
...

nginx.conf を編集したのでnginxを再起動

$ docker-compose restart nginx

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?