0

我是 Nginx 的新手,在允许 webhook 访问服务器时遇到了一些问题。每当 webhook 尝试向我的 Django 服务器发送 POST 时,我都会在访问日志中看到:

54.234.20.81 - - [02/Jan/2013:18:11:57 +0000] "POST /contracts/events HTTP/1.1" 403 2319 "-" "-" 54.234.20.81 - - [02/Jan/2013: 18:11:58 +0000] "POST /contracts/events HTTP/1.1" 403 2319 "-" "-" 54.234.20.81 - - [02/Jan/2013:18:11:58 +0000] "POST /contracts /事件 HTTP/1.1" 403 2319 "-" "-"

我不确定如何授予对该 IP 的访问权限,以免被禁止。我在 Ramhost 上托管,Nginx 目录似乎是 /etc/nginx/。该目录有一个 nginx.conf,还有一个站点可用文件夹和一个站点启用文件夹。

这是 sites-available 中的配置文件(在 sites-enabled 中有一个符号链接到此文件):

upstream djangoserv {
server 127.0.0.1:8080;
}

server {
    listen 80;
    server_name nameblr.com www.nameblr.com;
    access_log /home/yorango/yorangosite/logs/yorangosite-access.log;
    error_log /home/yorango/yorangosite/logs/yorangosite-error.log;

    location /static/ {
        alias /home/yorango/yorangosite/static/;
        expires 30d;
    }

    location /media/ {
        alias /home/yorango/yorangosite/static/;
        expires 30d;
    }

    location / {
        # host and port to fastcgi server
        allow 54.242.81.184;
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:8080;
        fastcgi_param PATH_INFO $fastcgi_script_name;
        fastcgi_param REQUEST_METHOD $request_method;
        fastcgi_param QUERY_STRING $query_string;
        fastcgi_param SERVER_NAME $server_name;
        fastcgi_param SERVER_PORT $server_port;
        fastcgi_param SERVER_PROTOCOL $server_protocol;
        fastcgi_param CONTENT_TYPE $content_type;
        fastcgi_param CONTENT_LENGTH $content_length;
        fastcgi_pass_header Authorization;
        fastcgi_intercept_errors off;
        fastcgi_split_path_info ^()(.*)$;
    }
}

这是 nginx.conf 文件,它位于 /etc/nginx/ 文件夹中。

user www-data;
worker_processes  1;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
    # multi_accept on;
}

http {
    include       /etc/nginx/mime.types;

    access_log  /var/log/nginx/access.log;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    tcp_nodelay        on;

    gzip  on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

我不确定“允许 54.242.81.184;”是否 是在正确的位置,或者sites-available 中的文件如何与nginx.conf 一起工作,但感谢任何帮助!

4

1 回答 1

2

你确定问题是 Nginx 吗?您是否为您的 Django 项目启用了 CSRF 保护?我很确定当 CSRF 检查失败时 Django 会发出 403。

查看这个问题以获取更多信息:Django CSRF check failed with an Ajax POST request

于 2013-01-02T18:40:37.927 回答