0

Django version is 1.10.3

Static file server is nginx

Debug mode off

The output media url has an absolute path in the server.

eg: http://127.0.0.1:8001/home/ken/hc/media/uploads/q/2017/03/01/hjqtye.png

The correct url is: http://127.0.0.1:8001/media/uploads/q/2017/03/01/hjqtye.png

How can i fix it? THX.

The relevant code as below.

settings.py

INSTALLED_APPS = [
    'grappelli',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'ckeditor',
    'ckeditor_uploader',
    'imagekit',
    'debug_toolbar',
    'gunicorn',
    'Website',
]

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'collected_static')
STATICFILES_DIRS = [(os.path.join(BASE_DIR, 'collected_static'))]
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
CKEDITOR_UPLOAD_PATH = "uploads/"
#CKEDITOR_UPLOAD_PATH = os.path.join(BASE_DIR, MEDIA_ROOT, 'uploads')

Nginx conf file

server {
    listen  8001;
    server_name 127.0.0.1;
    access_log /var/log/nginx/hc.access.log;
    error_log /var/log/nginx/hc.error.log;

location / {
        #uwsgi_pass  127.0.0.1:8010;
        #include uwsgi_params;
        proxy_pass http://127.0.0.1:8010;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location /media/  {
        alias /home/ken/hc/media/;
        expires 1h;
        access_log off;
        #add Cache-Control 'public';
    }

    location /static/ {
        alias /home/ken/hc/collected_static/;
        expires 1h;
        access_log off;
        #include /etc/nginx/mime.types;
        #add Cache-Control 'public';
    }
}
zofan
  • 31
  • 1
  • 3
  • Actually, Here is the anwser someone posted. http://stackoverflow.com/questions/5517950/django-media-url-and-media-root – zebo zhuang Mar 01 '17 at 03:37
  • Thank, the problem is solved, but solution not in this post, i try change correct url in the ckediter, maybe it was my carelessness, now it working well. – zofan Mar 01 '17 at 04:25

0 Answers0