Gunicorn throws error 403 when accessing static files

Gunicorn throws error 403 when accessing static files

I have a django project at my job written not by me. It was in eventcat user's home directory and with time we ran out of available space on the disk. I was to move the project to /data/. After I moved the project directory and set up a new environment I faced the problem that static files are not loaded and throwing 403 forbidden error.

python==2.7.5, django==1.11.10, gunicorn==19.7.1, RHEL 7.4

I have a django project at my job written not by me. It was in eventcat user's home directory and with time we ran out of available space on the disk. I was to move the project to /data/. After I moved the project directory and set up a new environment I faced the problem that static files are not loaded and throwing 403 forbidden error.

Well, I know that gunicorn is not supposed to serve static files on production, but this is an internal project with low load. I have to deal with it as is.

The server is started with a selfwritten script (I changed the environment line to new path):

#!/bin/sh

. ~/.bash_profile . /data/eventcat/env/bin/activate exec gunicorn -c gunicorn.conf.py eventcat.wsgi:application

The gunicorn.conf.py consists of:

bind = '127.0.0.1:8000'
backlog = 2048
workers = 1
worker_class = 'sync'
worker_connections = 1000
timeout = 120
keepalive = 2
spew = False
daemon = True
pidfile = 'eventcat.pid'
umask = 0
user = None
group = None
tmp_upload_dir = None
errorlog = 'er.log'
loglevel = 'debug'
accesslog = 'ac.log'
access_log_format = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"'
proc_name = None 

def post_fork(server, worker): server.log.info("Worker spawned (pid: %s)", worker.pid)

def pre_fork(server, worker): pass

def pre_exec(server): server.log.info("Forked child, re-executing.")

def when_ready(server): server.log.info("Server is ready. Spawning workers")

def worker_int(worker): worker.log.info("worker received INT or QUIT signal") import threading, sys, traceback id2name = dict([(th.identm, th.name) for th in threading.enumerate()]) code = [] for threadId, stack in sys._current_frames().items(): code.append("\n# Thread: %s(%d)" % (id2name.get(threadId, ""), threadId)) for filename, lineno, name, line in traceback.exctract_stack(stack): code.append('File: "%s", line %d, in %s' %(filename, lineno, name)) if line: code.append(" %s" % (line.strip())) worker.log.debug("\n".join(code))

def worker_abort(worker): worker.log.info("worker received SIGABRT signal")

All the files in static directory are owned by eventcat user just like the directory itself. I couldn't find any useful information in er.log and ac.log.

The server is running on https protocol and there is an ssl.conf in project directory. It has aliases for static and media pointing to previous project location and I changed all these entries to the new ones. Though I couldn't find where this config file is used.

Please, advise how can I find out what is the cause of the issue. What config files or anything should I look into?

python django

What's new in Bootstrap 5 and when Bootstrap 5 release date?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Random Password Generator Online

HTML Color Picker online | HEX Color Picker | RGB Color Picker

Python Django Tutorial | Django Course

🔥Intellipaat Django course: https://intellipaat.com/python-django-training/ 👉This Python Django tutorial will help you learn what is django web development &...

Basic Data Types in Python | Python Web Development For Beginners

In the programming world, Data types play an important role. Each Variable is stored in different data types and responsible for various functions. Python had two different objects, and They are mutable and immutable objects.

Developing Restful APIs with Python, Django and Django Rest Framework

This article is a definitive guide for starters who want to develop projects with RESTful APIs using Python, Django and Django Rest Framework.

How to run a python script in django propject which has multiple django models in it

I have a script that I want to run from terminal inside a django project and that script is a python script and it has multiple django models in it .So how can I run that script since I am not able to run it directly.Also everything resides inside docker container.