Gunicorn在访问静态文件时抛出错误403



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

我的工作中有一个django项目不是我写的。它在eventcat用户的主目录中,随着时间的推移,磁盘上的可用空间用完了。我打算把这个项目转移到/data/。在我移动了项目目录并建立了一个新的环境后,我面临着静态文件未加载和抛出403 forbidden错误的问题。

嗯,我知道gunicorn不应该在生产中提供静态文件,但这是一个低负载的内部项目。我必须按原样处理。

服务器以一个自写脚本启动(我将环境行更改为新路径):

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

gunicorn.conf.py包括:

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")

static目录中的所有文件都由eventcat用户所有,就像目录本身一样。我在er.logac.log中找不到任何有用的信息。

服务器运行在https协议上,项目目录中有一个ssl.conf。它有指向以前项目位置的staticmedia的别名,我将所有这些条目都更改为新条目。尽管我找不到这个配置文件的使用位置。

请告知我如何找出问题的原因。我应该查看哪些配置文件或任何内容?

更新:多亏了@ruddra,gunicorn根本没有提供静态服务。是httpd。在httpd-config中进行更改后,一切都正常工作。

据我所知,gunicorn不提供静态内容。因此,要提供静态内容,最好使用whiteoise,也可以使用NGINX、Apache或任何反向代理服务器。您可以使用NGINX查看Gunicorn的部署文档。

如果你想使用whiteoise,那么请使用安装

pip install whitenoise

然后像这样(在settings.py内部)向MIDDLEWARES添加白噪声:

MIDDLEWARE = [
# 'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
# ...
]

相关内容

最新更新