【发布时间】:2016-01-02 07:08:06
【问题描述】:
我正在采取最后一步来公开我的页面,但是在设置 nginx + gunicorn 之后,我得到了要加载的页面,但是没有任何 css 正在加载,即使我的 nginx-log 文件没有显示错误。
这是我的nginx.conf:
server {
listen 8000;
server_name 127.0.0.1;
access_log /<direct_path>/logs/nginx-access.log; # <- make sure to create the logs directory
error_log /<direct_path>/logs/nginx-error.log; # <- you will need this file for debugging
location / {
proxy_pass http://127.0.0.1:9000; # <- let nginx pass traffic to the gunicorn server
}
location /static {
alias /<project path>/chemicalizer; # <- let nginx serves the static contents
}
}
还有我的 gunicorn.conf.py,与 manage.py 位于同一目录:
bind = "127.0.0.1:9000"
errorlog = '/<direct_path>/logs/gunicorn-error.log'
accesslog = '/<direct_path>/logs/gunicorn-access.log'
loglevel = 'debug'
workers = 4
还有我的项目settings.py 文件
import os, djcelery
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Celery setup
djcelery.setup_loader()
BROKER_URL = 'amqp://guest:guest@localhost:5672'
SECRET_KEY = censored...
DEBUG = False
ALLOWED_HOSTS = ['0.0.0.0', '127.0.0.1', 'localhost']
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.sites',
'django.contrib.staticfiles',
'interface',
'chemrun',
'djcelery',
'kombu.transport.django',
'chemicalizer.tasks',
'json',
'django_nvd3',
'djangobower',
'allauth',
'allauth.account',
'djangosecure',
)
MIDDLEWARE_CLASSES = (
'djangosecure.middleware.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
ROOT_URLCONF = 'chemicalizer.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['interface'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
非常感谢任何帮助。不确定可能需要显示哪些其他文件,因此请告诉我是否应该包含其他文件。
更新
再环顾一番后,我发现我的css 文件是由nginx 加载和提供的,但不知何故,html 或gunicorn 并没有发挥作用。如果我使用Chrome's "developer tools" 查看 html 页面的内容,我发现 css 文件在网络part 中定位并成功加载,但在sources 选项卡中css 文件为空。
我还看到我的gunicorn-access.log 没有为css 文件发送GET 命令,当我运行@987654337 时代码没有问题时,是否有原因不会发生这种情况@?
【问题讨论】:
-
静态文件的系统路径是什么?
-
/Users/tobias/Dropbox/Science/PythonWorkspace/NewChemicalizer/chemicalizer/static
标签: css django nginx static gunicorn