设置Apache配置以使用Gunicorn代理服务/ static Django文件时出现问题

时间:2019-05-18 16:27:07

标签: django apache gunicorn

正如标题所述,我很难正确设置Apache设置,以使用后端的Gunicorn代理为生产中的Django静态文件提供服务。

我发现当我切换DEBUG = False时,该应用程序退出使用:< unexpected token。读到它,与STATIC_ROOT的使用不正确有关。

我有STATIC_ROOT = os.path.join(BASE_DIR, 'static'),并且正在运行python manage.py collectstatic,它将所有资产收集到项目根目录中的/static。然后,我在与gunicorn wsgi -D相同的目录中运行wsgi.py

无论如何,这是设置Apache配置的方式:

HTTP

ServerName www.website.com
ServerAlias website.com

### Redirect http to https

RewriteEngine On
# This will enable the Rewrite capabilities

RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS

RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
# This rule will redirect users from their original location, to the same location but using HTTPS.
# i.e.  http://www.example.com/foo/ to https://www.example.com/foo/
# The leading slash is made optional so that this will work either in httpd.conf
# or .htaccess context

HTTPS

ServerName www.website.com
ServerAlias website.com

Alias /static /home/website/src/static

ProxyPreserveHost On
ProxyPass /static http://localhost:8000/static/
ProxyPass / http://localhost:8000/ retry=5
ProxyPassReverse / http://localhost:8000/
<Proxy *>
    Order deny,allow
    Allow from all
</Proxy>

我在这里做什么错了?

0 个答案:

没有答案