1
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?

More than 5 years have passed since last update.

[Django]デプロイしたサイトのレイアウトが壊れた(静的ファイルが読み込めない)時の対処法[CentOS7][Apache2.4]

Posted at

環境

  • Django 2.1
  • CentOS 7
  • Python 3.6
  • Apache 2.4
  • mod_wsgi 4.6.5

対処法

静的ファイルをApacheで配信する設定に変更する

1. Apacheの設定ファイルを開く(設定ファイルの場所)

下記のファイルは自分で作成するファイルです。
おそらくこの記事を読んでいる人の大半は既に作成していると思いますが、無い人は作成しましょう。

vi /etc/httpd/conf.d/xxx.conf

2. Apacheの設定ファイルを編集する

設定ファイルの基本的な書き方は他の記事に委ねます。
ここでは、静的ファイルをApacheに配信させる設定のみに焦点を当てています。

また、mysite/settings.pyを下記のように設定していることを前提とします。

STATIC_URL = '/static/'
1. adminと自作のmyappの静的ファイルを同じ場所に格納している場合(もしくは一方のみの場合)
    Alias /static /var/www/mysite/static
    <Directory /var/www/mysite/static>
        Require all granted
    </Directory>
2. adminと自作のmyappの静的ファイルを別場所に格納している場合
Alias /static/admin /var/www/mysite/static/admin
<Directory /var/www/mysite/static/admin>
    Require all granted
</Directory>

Alias /static/myapp /var/www/mysite/myapp/static/myapp
<Directory /var/www/mysite/myapp/static/myapp>
    Require all granted
</Directory>
1
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
1
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?