StamusNetworks / scirius

Scirius is a web application for Suricata ruleset management and threat hunting.
GNU General Public License v3.0
621 stars 148 forks source link

Fails to collect and serve static files #169

Closed bartwalczak closed 5 years ago

bartwalczak commented 5 years ago

I tried to follow manual installation steps and build my own docker image, as well as using the scirius-docker. Regardless of everything, the server fails to serve static files, even though the website itself is working.

I narrowed it down to this: When running python manage.py collectstatic the following error is shown and the static files are not collected:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 199, in handle
    collected = self.collect()
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 124, in collect
    handler(path, prefixed_path, storage)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 354, in copy_file
    if not self.delete_file(path, prefixed_path, source_storage):
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 260, in delete_file
    if self.storage.exists(prefixed_path):
  File "/usr/local/lib/python2.7/dist-packages/django/core/files/storage.py", line 392, in exists
    return os.path.exists(self.path(name))
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/storage.py", line 50, in path
    raise ImproperlyConfigured("You're using the staticfiles app "
django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.

Any help would be appreciated.

biolds commented 5 years ago

As the error says, you need to set the STATIC_ROOT configuration option (in local_settings.py), it should point to the directory where static files are served. You can find more information in Django's documentation about it : https://docs.djangoproject.com/en/2.1/ref/settings/#static-root

lukelee1987 commented 5 years ago

Sorry to ask, may I know what is the expected output?

bartwalczak commented 5 years ago

It turns out that I was trying to follow the outdated docker image. When I changed

gunicorn -w $(($(nproc --all)*2+1)) -t 120 -b 0.0.0.0:8000 scirius.wsgi

into

python manage.py runserver

Then the whole collectstatic step turned out to be unnecessary. So the @biolds comment was totally off the mark (I tried the obvious suggested solution but it didn't work).

biolds commented 5 years ago

@bartwalczak using runserver works, but it's supposed to be used as a development server. As the Django documentation states: DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through security audits or performance tests. (https://docs.djangoproject.com/en/2.1/ref/django-admin/#runserver). The way to go, is to run a wgsi server (gunicorn) behind a reverse proxy, and have STATIC_ROOT point to the static file dir.

bartwalczak commented 5 years ago

Well, that solution didn't work for me. I'm not going to pursue this further, as I managed to test the software and realized that it is not what I am looking for.