1

我刚刚尝试了很多东西。希望你们能帮我解决这个问题。

我有一个典型的问题,为我的 django 1.5 项目提供静态文件。例如,我正在尝试获取一个 css 文件,它会抛出 404。

我的 nginx 配置:

server {
    listen *:80;

    server_name t1.bpt.local www.t1.bpt.local;
    root /srv/sites/bikepolo_tournament-t1;
    index index.html index.htm index.php index.cgi index.pl index.xhtml;

    error_log /var/log/nginx/t1.bpt.local-error.log;
    access_log /var/log/nginx/t1.bpt.local-access.log combined;

    ## Disable .htaccess and other hidden files
    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location /static/ {
        autoindex on;
        alias /srv/sites/bikepolo_tournament-t1/bikepolo_tournament/assets;
    }


    location / {
        proxy_pass_header Server;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Scheme $scheme;
        proxy_connect_timeout 10;
        proxy_read_timeout 10;
        proxy_pass http://localhost:8100;
    }
}

我的主管 conf 文件:

[program:bikepolo_tournament_t1]
directory=/srv/sites/bikepolo_tournament-t1
command=/srv/sites/bikepolo_tournament-t1/deploy/start_gunicorn_t1.sh
autostart=true
user=tom
stdout_logfile = /var/log/supervisor/%(program_name)s.log
stderr_logfile = /var/log/supervisor/%(program_name)s-error.log

主管命令文件:

#!/bin/bash

set -e

APP_NAME="bikepolo_tournament"
PROJ_NAME="bikepolo_tournament"
DIR_SUFFIX="-t1"

VENV_PROJECTS="/srv/sites"
VENV_DIR="/home/tom/venvs/bikepolo-tournament"
GUN_CONF_MODULE="deploy/gunicorn.conf.py"

PROJ_HOME=$VENV_PROJECTS/$PROJ_NAME$DIR_SUFFIX
WSGI_MODULE=$APP_NAME.wsgi

source $VENV_DIR/bin/activate

cd $PROJ_HOME
exec gunicorn -c $GUN_CONF_MODULE $WSGI_MODULE:application

gunicorn.conf.py:

import multiprocessing
import os
import sys


GB_BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

sys.path.append(os.path.join(GB_BASE_DIR, 'bikepolo_tournament'))

from settings import get_run_mode


_run_mode = get_run_mode() # getting 'prod', 'test' or 'dev'

if _run_mode == 'prod':
    _bind_port = '8101'
    _number_workers = 1 + multiprocessing.cpu_count() * 2
    _log_filename = 'gunicorn_www-error.log'
elif _run_mode == 'test' or _run_mode == 'dev':
    _bind_port = '8100'
    _number_workers = 1
    _log_filename = 'gunicorn_t1-error.log'
else:
    raise ValueError('Unexpected run mode: %s' % _run_mode)

debug = True

bind = '127.0.0.1:%s' % _bind_port

backlog = 1024
workers = _number_workers

我的 django 设置的相关部分:

here = lambda *x: os.path.join(os.path.abspath(os.path.dirname(__file__)), *x)
PROJECT_ROOT = here("..")
root = lambda *x: os.path.join(os.path.abspath(PROJECT_ROOT), *x)
STATIC_ROOT = root('static')
STATIC_URL = '/static/'

如果我什么都没忘记,那是我的设置让我头疼不已……

那么,我做错了什么?我忘记了什么?

提前致谢!

4

0 回答 0