小编gru*_*iba的帖子

django nginx 在生产环境中通过 http 获取 csrf 验证错误

我刚刚使用 nginx 在 AWS 上部署了 django 项目。一切正常,除了当我尝试发出任何 POST 请求(仅通过 http)时,我收到错误:

“禁止 (403) CSRF 验证失败。请求已中止。”

如果我直接使用 Django 运行我的服务器,CSRF 验证就会起作用,这让我认为我没有nginx.conf正确设置我的服务器。
有人可以指导我如何配置 nginx 来使用 csrf 吗?
这是我当前的配置:

#nginx.conf
upstream django {
    # connect to this socket
    server unix:///tmp/uwsgi.sock;    # for a file socket
    #server 127.0.0.1:8001;      # for a web port socket
    }
server {
    # the port your site will be served on
    listen 80;

    root /opt/apps/site-env/site;

    # the domain name it will serve for
    server_name mysite.org

    charset     utf-8;

    #Max upload …
Run Code Online (Sandbox Code Playgroud)

python django nginx amazon-ec2 web-deployment

6
推荐指数
1
解决办法
2515
查看次数

标签 统计

amazon-ec2 ×1

django ×1

nginx ×1

python ×1

web-deployment ×1