我在 django 1.6 中有一个应用程序,并且在实时 / admin / address上存在问题。
当我在现场转到此地址时会收到 404错误 。
Nginx日志说我没有文件或目录:
/path_to_project/live/admin/index.html"未找到(2:没有此类文件或目录)
在本地,一切正常,项目在admin目录中没有index.html文件。
请求帮助。
我的网址:
from django.conf.urls import patterns, include, url
from django.conf.urls.static import static
from django.conf import settings
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('presentationtool.urls')),
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
我的设置:
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCP
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = ['*']
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)
# Application definition
DEFAULT_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
THIRD_PARTY_APPS = (
'south',
'easy_thumbnails',
)
ADMIN_APPS = (
'suit',
'adminsortable',
)
LOCAL_APPS = (
'myapp',
)
INSTALLED_APPS = ADMIN_APPS + DEFAULT_APPS + THIRD_PARTY_APPS + LOCAL_APPS
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'www.urls'
WSGI_APPLICATION = 'www.wsgi.application'
TEMPLATE_CONTEXT_PROCESSORS = TCP + (
'django.core.context_processors.request',
'django.core.context_processors.static',
)
# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, '..', 'static')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, '..', 'media')
SOUTH_MIGRATION_MODULES = {
'easy_thumbnails': 'easy_thumbnails.south_migrations',
}
修改
我的nginx设置:
upstream myapp_upstream {
server my_url:port;
}
server {
include inc/80.inc;
server_name
my_url_here.com;
root /path_to_project_on_server/live/;
access_log /var/log/nginx/app/myapp.live.access.log;
error_log /var/log/nginx/app/myapp.live.error.log;
access_log /var/log/nginx/app/myapp.live.upstream.log upstream;
location / {
include uwsgi_params;
uwsgi_pass myapp_upstream ;
}
location /admin {
client_max_body_size 400m;
}
location /static/ {
alias /path_to_project_on_server/live/static/;
}
location /media {
alias /path_to_project_on_server/live/media;
}
# return 302 https://my_url_here.com$request_uri;
}
答案 0 :(得分:0)
您需要设置nginx以使用uWSGI在您的django设置中处理该路径上的任何请求。丢失的index.html消息似乎暗示nginx本身(而不是Django)正在尝试查找并提供一个不存在的索引文件。
似乎问题与nginx有关,而不是你的django设置。你是如何配置nginx的?
http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html
答案 1 :(得分:0)
确保您的回复返回正确的http状态。 有关完整的响应,请参见this issue。