[PYTHON] When I put Django in my home directory, I was addicted to static files with permission errors

As the title says A story when a Django application is placed under / home / ec2-user / on AWS WEB server uses Nginx

About handling static files when publishing Django applications

When publishing a Django application, static files

$ python manage.py collectstatic

Need to be put together somewhere

settings.py looks like this

settings.py


STATIC_URL = '/static/'

STATICFILES_DIRS=(
    os.path.join(BASE_DIR, "app/static/"),
)

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

By doing this, various css and js will be collected in / home / ec2-user / django_project_root / static and can be accessed under http: // domain / static.

Make nginx.conf accessible to static files as follows

nginx.conf


server {
	...
	location /static/ {
            autoindex   on;
            alias  /home/ec2-user/django_project_root/static/;
    }

But permission error

If you look at the state of the application because it can be done with this, css is not applied (403 forbidden) Looking at /var/log/nginx/error.log

2017/08/29 02:17:27 [error] 11629#0: *22 open() "/home/ec2-user/django_project_root/static/apps/css/base.css" failed (13: Permission denied), client: xx.xxx.xxx.xxx, server: xx.xxx.xxx.xxx, request: "GET /static/apps/css/base.css HTTP/1.1", host: "xx.xxx.xxx.xxx", referrer: "http://xx.xxx.xxx.xxx/"

I got a permission error like this

SElinux is bad when I try various googles, isn't it? There was an article like

$ getenforce
Disabled

Was disabled

I tried playing with the permissions of static files and playing with the permissions of the directory / home / ec2-user / django_project_root / static /, but the state did not change.

I had to give execute permission to / home / ec2-user /

The initial state is 700 (drwx ------), but it was necessary to give execute permission to other.

$ sudo chmod o+x /home/ec2-user/

with this

xx.xxx.xxx.xxx - - [29/Aug/2017:02:54:10 +0000] "GET /static/apps/css/login.css HTTP/1.1" 200 1203 "http://xx.xxx.xxx.xxx" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36" "-"

Yes You can now safely access static files

It was a rudimentary story that even if you have execute permission to the child directory, you can not "move to the directory itself" without execute permission to the parent directory ...

Recommended Posts

When I put Django in my home directory, I was addicted to static files with permission errors
I was addicted to scraping with Selenium (+ Python) in 2020
What I did when I was angry to put it in with the enable-shared option
How to handle static files when deploying to production with Django
What I was addicted to with json.dumps in Python base64 encoding
A note I was addicted to when creating a table with SQLAlchemy
What I was addicted to when creating a web application in a windows environment
Three things I was addicted to when using Python and MySQL with Docker
A note I was addicted to when running Python with Visual Studio Code
A story that I was addicted to when I made SFTP communication with python
What I was addicted to when combining class inheritance and Joint Table Inheritance in SQLAlchemy
How to reference static files in a Django project
I was addicted to trying logging.getLogger in Flask 1.1.x
What I was addicted to when using Python tornado
When I tried to install PIL and matplotlib in a virtualenv environment, I was addicted to it.
When I deploy a Django app with Apache2 and it no longer reads static files
[IOS] GIF animation with Pythonista3. I was addicted to it.
What I was addicted to when migrating Processing users to Python
I can't log in to the admin page with Django3
What I was addicted to when I built my own neural network using the weights and biases I got with scikit-learn's MLP Classifier.
What I was addicted to in Collective Intelligence Chaprter 3. It's not a typo, so I think something is wrong with my code.
When I tried to scrape using requests in python, I was addicted to SSLError, so a workaround memo
The record I was addicted to when putting MeCab on Heroku
What I was addicted to when introducing ALE to Vim for Python
A note I was addicted to when making a beep on Linux
I was addicted to confusing class variables and instance variables in Python
[Python] When I tried to make a decompression tool with a zip file I just knew, I was addicted to sys.exit ()
Errors related to memcached in django
I was addicted to multiprocessing + psycopg2
I want to get angry with my mom when my memory is tight
Two things I was addicted to building Django + Apache + Nginx on Windows
I put Alpine Linux in Larkbox and made it my home server
I was addicted to running tensorflow on GPU with NVIDIA driver 440 + CUDA 10.2
A story I was addicted to when inserting from Python to a PostgreSQL table
I was addicted to creating a Python venv environment with VS Code
A story I was addicted to trying to get a video url with tweepy
Use Python from Java with Jython. I was also addicted to it.
I want to use the Django Debug Toolbar in my Ajax application
The file name was bad in Python and I was addicted to import
I was addicted to trying Cython with PyCharm, so make a note
In IPython, when I tried to see the value, it was a generator, so I came up with it when I was frustrated.
Notes on creating static files in Django
I was addicted to pip install mysqlclient
I was addicted to Flask on dotCloud
What I was addicted to Python autorun
Permission error when reading Django upload files
I got an error when I put opencv in python3 with Raspberry Pi [Remedy]
I referred to it when I got stuck in the django geodjango tutorial (editing)
How to get a list of files in the same directory with python