I’m new to Nginx, and I am having some problems allowing a webhook access to the server. Whenever the webhook tries to send a POST to my Django server, I get this in my access log:
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/events HTTP/1.1” 403 2319 “-” “-“
I’m not sure how to grant access to this IP such that it is not forbidden. I’m hosting on Ramhost, and the Nginx directory appears to be /etc/nginx/. This directory has a nginx.conf, and also a sites-available folder and a sites-enabled folder.
Here is the configuration file in sites-available (there is a symlink in sites-enabled to this file):
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 ^()(.*)$;
}
}
And here is the nginx.conf file, which is in the /etc/nginx/ folder.
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/*;
}
I’m not sure if the “allow 54.242.81.184;” is in the correct place, or how the file in sites-available works together with the nginx.conf, but any help is appreciated!!
Are you sure the problem is Nginx? Do you have CSRF protection enabled for your Django project? I’m pretty sure Django will emit a 403 when the CSRF-check fails.
Check out this question for more info: Django CSRF check failing with an Ajax POST request