Django版本是1.10.3
静态文件服务器是nginx
关闭调试模式
输出媒体网址在服务器中具有绝对路径。
例如:http://127.0.0.1:8001/home/ken/hc/media/uploads/q/2017/03/01/hjqtye.png
正确的网址是:http://127.0.0.1:8001/media/uploads/q/2017/03/01/hjqtye.png
我该如何解决?谢谢。
相关代码如下。
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配置文件
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';
}
}