0

I have an application in django 1.6 and a problem with /admin/ address on live.

When I go to this address on the live gets a 404 error.

Nginx log says that I have no file or directory:

/path_to_project/live/admin/index.html "not found (2: No such file or directory)

Locally, everything works and the project does not have the index.html file in the admin directory.

Please for help.

My urls:


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)

My settings:


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',
}

EDIT

My nginx settings:

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;

}
Kai
  • 553
  • 3
  • 7
  • 15
  • what happens if you load up only `yourLiveURL/admin`? – N. Ivanov Sep 21 '17 at 09:59
  • @N.Ivanov I recived `2017/09/21 11:59:39 [error] 1909#0: *25969334 open() "/path_to_project/live/admin" failed (2: No such file or directory),` and 404 error. – Kai Sep 21 '17 at 10:01
  • do any of the other pages load up? non admin ones? – N. Ivanov Sep 21 '17 at 10:04
  • @N.Ivanov Main page looks ok, but I have problem with this `/admin/` url – Kai Sep 21 '17 at 10:06
  • try [This](https://serverfault.com/questions/403264/nginx-not-serving-admin-static-files), might have something useful – N. Ivanov Sep 21 '17 at 10:08
  • Django configurations seem to be fine, ensure the rest of your site urls are reachable. Do presentationtool urls work? PS: Django 1.6 is no longer supported. Please upgrade to a newer release if you can! – Dos Sep 22 '17 at 15:34

2 Answers2

0

You would need to setup nginx to have any requests at that path to be handled by your django setup using uWSGI. The missing index.html message seems to suggest nginx itself (rather than Django) is trying to find and serve an index file, which doesn't exist.

It seems the issue is related to nginx rather than your django setup. How have you configured nginx?

http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html

BrendanBenting
  • 571
  • 6
  • 8
0

Make sure your response returns the correct http status. See this issue for complete response.

Julien Kieffer
  • 1,116
  • 6
  • 16