Answer the question
In order to leave comments, you need to log in
How to enable site statics on a production server?
The crux of the issue is in the title. I'm trying to install on a local Ubuntu machine. So far, to complete the task, the following has been done according to the instructions:
I registered a new directory for statics in settings.py:
STATIC_ROOT = '/opt/mag/static/'
But when I try to collect statics:
python manage.py collectstatic
An error appears:
Copying '/home/anton/virtenvs/mag_env/lib/python3.5/site-packages/django/contrib/admin/static/admin/fonts/LICENSE.txt'
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/anton/virtenvs/mag_env/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/home/anton/virtenvs/mag_env/lib/python3.5/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/anton/virtenvs/mag_env/lib/python3.5/site-packages/django/core/management/base.py", line 305, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/anton/virtenvs/mag_env/lib/python3.5/site-packages/django/core/management/base.py", line 356, in execute
output = self.handle(*args, **options)
File "/home/anton/virtenvs/mag_env/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 193, in handle
collected = self.collect()
File "/home/anton/virtenvs/mag_env/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 124, in collect
handler(path, prefixed_path, storage)
File "/home/anton/virtenvs/mag_env/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 347, in copy_file
self.storage.save(prefixed_path, source_file)
File "/home/anton/virtenvs/mag_env/lib/python3.5/site-packages/django/core/files/storage.py", line 54, in save
return self._save(name, content)
File "/home/anton/virtenvs/mag_env/lib/python3.5/site-packages/django/core/files/storage.py", line 321, in _save
os.makedirs(directory)
File "/home/anton/virtenvs/mag_env/lib/python3.5/os.py", line 231, in makedirs
makedirs(head, mode, exist_ok)
File "/home/anton/virtenvs/mag_env/lib/python3.5/os.py", line 231, in makedirs
makedirs(head, mode, exist_ok)
File "/home/anton/virtenvs/mag_env/lib/python3.5/os.py", line 231, in makedirs
makedirs(head, mode, exist_ok)
File "/home/anton/virtenvs/mag_env/lib/python3.5/os.py", line 241, in makedirs
mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/opt/mag'
server {
listen 8000;
server_name 192.168.10.5; #либо ip, либо доменное имя
access_log /var/log/nginx/example.log;
location /static/ {
root /home/anton/Django-u/magazine/main_site/;
expires 30d;
}
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
python manage.py runserver
there are no problems with statics. Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question