我一直在获取 django.request:ForbIDden(Referer检查失败 – 没有Referer.)用于POST多部分表单请求.
我正在使用AWS ELB(d性负载平衡器),Nginx(我的ec2(在autoscailing组中)和Gunicorn.
AWS ELB侦听器设置如下所示(仅限httpS):
elb https only listener setting
Nginx设置如下:
user Nginx;worker_processes auto;error_log /var/log/Nginx/error.log;pID /var/run/Nginx.pID;events { worker_connections 1024;}http { include /etc/Nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/Nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/Nginx/conf.d/*.conf; index index.HTML index.htm; upstream my_server { server localhost:8000; } server { Listen 80; server_name <server name>; access_log /etc/Nginx/log/local-wc.access.log; error_log /etc/Nginx/log/local-wc.error.log; root /usr/share/Nginx/HTML; location /API/v1 { proxy_pass http://my_server/API/v1; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Protocol $scheme; } }}
<服务器名称>是指向elb DNS名称的Cname.
换句话说,<服务器名称> => xxxx-123456789.us-west-2.elb.amazonaws.com(记录).
每个API调用都是通过https://< server name> / API / v1 / *进行的
最后Gunicorn正在经营:
gunicorn my_django_app.wsgi:application -w 1 -b 127.0.0.1:8000 -t 300 –max-requests = 100
和Django设置是:
ALLOWED_HOSTS = ['*']SECURE_PROXY_SSL_header = ('http_X_FORWARDED_PROTO','https')MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.mIDdleware.SessionMIDdleware','django.mIDdleware.common.CommonMIDdleware','django.mIDdleware.csrf.CsrfVIEwMIDdleware','django.contrib.auth.mIDdleware.AuthenticationMIDdleware','django.contrib.auth.mIDdleware.SessionAuthenticationMIDdleware','django.contrib.messages.mIDdleware.MessageMIDdleware','django.mIDdleware.security.SecurityMIDdleware',)
查看功能如下(使用CSRF免除):
class UserVIEwSet(CsrfExemptMixin,mixins.CreateModelMixin,mixins.ListModelMixin,mixins.RetrIEveModelMixin,mixins.UpdateModelMixin,vIEwsets.GenericVIEwSet): # already trIEd @csrf_exempt def create(self,request,*args,**kwargs): self.parser_classes = (FormParser,MultiPartParser,) .........
再次出问题:
当我发送
curl -i -k -X POST -H "Accept: application/Json" \ -F "email=myemail@email.com" \ -F "profile_img=@profile.jpg" \ https://<server name>/API/v1/users/
在我的Django日志中:
[WARNING] django.request: ForbIDden (Referer checking Failed - no Referer.): /API/v1/users/
它适用于http上的POST或httpS上的GET方法.
我想知道ELB配置是错误的还是Nginx配置错误的引用…
如果有人帮我解决这个问题,我将不胜感激.
以上是内存溢出为你收集整理的django.request:Forbidden(Referer check failed – 没有Referer.)全部内容,希望文章能够帮你解决django.request:Forbidden(Referer check failed – 没有Referer.)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)