Djangoで作成したアプリをデプロイしたのですが、staticファイルを読み込んでくれません。(もちろん、開発環境においては、staticファイルは読み込まれています。)
サーバーは、Ubuntu serverで、nginx、gunicornで動いています。
https://docs.nginx.com/nginx/admin-guide/web-server/app-gateway-uwsgi-django/
上記のnginxのドキュメントを見て、
/etc/nginx/sites-enabled/default
に、下記のとおり記載をしてみました。
location /static/ { alias /myproject/testproject/test/static/; }
また、
/testproject/urls.py
には、下記のように記載しています。
urlpatterns = [ ]+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
この上で、サーバー上でpython manage.py collectstaticを実行しました。
You have requested to collect static files at the destination
location as specified in your settings:
/home/username/myproject/testproject/test/static
This will overwrite existing files!
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: yes
Copying '/home/username/myproject/testproject/lib/python3.5/site-packages/jet/static/admin/css/forms.css'
……
Found another file with the destination path 'admin/css/forms.css'. It will be ignored since only the first encountered file is collected. If this is not what you want, make sure every static file has a unique path.
……
Copying '/home/username/myproject/archifields/lib/python3.5/site-packages/django/contrib/admin/static/admin/img/gis/move_vertex_off.svg'
……
444 static files copied to '/home/username/myproject/testproject/test/static', 2932 unmodified.
と表示され、collectstaticはうまく動いているように見えます。
その後、ページにアクセスすると、画像は表示されないのですが、レンダリングされたhtmlを見て、画像が表示されるべきURLに行くと、
<h1>Not Found</h1><p>The requested URL /test/static/images/open-iconic/svg/question-mark.svg was not found on this server.</p> と表示されます。 しかし、サーバー上で見ると、/test/static/images/open-iconic/svg/question-mark.svgは確かにあります。 なぜ、うまくいかなかったのでしょうか。 何かお気づきの点がある方、ご教示頂ければ幸いです。
なお、/var/log/nginx/error.log.1を見てみると、下記のエラーが表示されます。
2018/05/06 15:12:38 [error] 27881#27881: *20099 open() "/myproject/testproject/test/static/css/style.css" failed (2: No such file or directory), client: 66.249.79.92, server: www.testproject.com, request: "GET /static/css/style.css HTTP/1.1", host: "www.sample.jp", referrer: "http://www.sample.jp/specific_tag/10060031/"
myproject/testproject/test/static/css/style.cssを見ているのですが、そこにstyle.cssはあるはずですので、なぜなのか分かりません。


回答1件
あなたの回答
tips
プレビュー