我刚刚使用 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)