【发布时间】:2015-01-15 08:15:15
【问题描述】:
现在我正在处理 Django 项目,这是我第一次通过 gunicorn 在服务器 (Lighttpd) 上运行 Django 应用程序。问题是 - 我像这样使用 gunicorn 运行应用程序:
$PYTHON $MANAGEPATH run_gunicorn -D -b 127.0.0.1:18002 -p $GUNICORN_PIDPATH --log-file $GUNICORN_LOGPATH
Django settings.py 的一部分:
from __future__ import absolute_import
import os
from socket import gethostname
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
HOSTNAME = gethostname()
def make_path(path):
return os.path.join(BASE_DIR, path)
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = make_path('static_root')
# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = '/static/'
在 /etc/lighttpd/vhost.d/my_conf.conf 我对非静态文件有很好的重定向:
$SERVER["socket"] == ":82" {
server.document-root = "/home/mefioo/public_html/generator/static"
$HTTP["url"] !~ "\.(js|css|gif|jpg|png|ico|txt|swf|html|htm|svg|xlsx)$" {
proxy.server = ("" => ( "localhost" => (
"host" => "127.0.0.1",
"port" => 18002,
"fix-redirects" => 1
) ) )
}
}
想法 - .js 或 .css 等静态文件位于
/home/mefioo/public_html/generator/static
(它是 Django 应用程序中 static_root 目录的代理)并且应该可以从 url 中获得,例如
my_domain.com:82/my_file.js
应用程序的其余部分,所有网址如下:
my_domain.com:82/url
应该寻找这样的 django 应用程序:
127.0.0.1:18002/url
因为 lighttpd conf。
问题是 - 当我尝试访问我的静态文件时,我得到了 404,因为应用程序正在寻找
localhost:8080/my_file.js
而不是
my_domain.com:82/my_file.js
我不明白为什么,尤其是当我有该应用程序的两个实例时,一个在我自己的服务器上(第二台 PC,不工作),一个在外部 VPS 上(按预期工作)。我是以错误的方式运行 gunicorn,还是在 lighttpd 设置中遗漏了什么?
【问题讨论】:
标签: django lighttpd gunicorn static-files