2012-07-22 152 views
3

我正在为一个侧面项目膳食规划工具放在一起的PoC。我使用nginx和uwsgi在AWS上运行的django。该网站正在运行并加载页面,但没有传递给浏览器的CSRF cookie。Django后面uwsgi + nginx无法设置cookie

CSRF和消息中间件都启用,并且django调试输出列出了'CSRF_COOKIE'的值,并且我的浏览器启用了cookie,所以我怀疑Django试图设置一个cookie, nginx或uwsgi。

配置如下信息:

uwsgi.ini

[uwsgi] 
chdir=/opt/django/mealplanner/src/mealplanner/ 
module=mealplanner.wsgi:application 
master=True 
autoload=True 
pidfile=/opt/run/mealplanner.pid 
vacuum=True 
max-requests=5000 
socket=/opt/run/mealplanner.sock 
chmod-socket=True 
harakiri=120 
processes=1 
home=/opt/django/mealplanner/src 
daemonize=/opt/log/uwsgi/mealplanner.log 

nginx.conf

user www-data; 
worker_processes 1; 
pid /opt/run/nginx.pid; 

events { 
     worker_connections 768; 
     # multi_accept on;                     
} 

http { 

     ##                         
     # Basic Settings                     
     ##                         

     sendfile on; 
     tcp_nopush on; 
     tcp_nodelay on; 
     keepalive_timeout 65; 
     types_hash_max_size 2048; 
     # server_tokens off;                    

     # server_names_hash_bucket_size 64;                 
     # server_name_in_redirect off;                  

     include /etc/nginx/mime.types; 
     default_type application/octet-stream; 

     ##                         
     # Logging Settings                     
     ##                         

     access_log /opt/log/nginx/access.log; 
     error_log /opt/log/nginx/error.log; 

     ##                         
     # Gzip Settings                      
     ##                         

     gzip on; 
     gzip_disable "msie6"; 

     # gzip_vary on;                      
     gzip_proxied any; 
     gzip_comp_level 2; 
     # gzip_buffers 16 8k;                    
     # gzip_http_version 1.1;                   
     gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml \ 
application/xml+rss text/javascript; 

     server { 
       listen 80; 
       # I've also tried the dns name I access the site with as the server name. 
       server_name ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com xx.xx.xx.xx; 
       client_max_body_size 50M; 
       set $home /opt/django/mealplanner; 
       root $home; 
       location/{ 
         include uwsgi_params; 
         uwsgi_pass unix://opt/run/mealplanner.sock; 
         root $home; 
       } 
     } 

     ##                         
     # Virtual Host Configs                    
     ##                         

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

当你说你在AWS上运行它时,你的意思是单个EC2实例吗? – jamieb 2012-07-22 23:05:16

+0

是的它使用EC2微。我只是偶然发现我认为我做错了什么。 – Peter 2012-07-23 01:18:35

回答

2

它看起来像这个问题有可能会一直在nginx.conf的服务器名称。它突然开始工作,我改变了唯一的做法是使server_name匹配站点的域名。另一方面,改回它似乎没有重新引入这个问题,所以要么我没有正确地重新启动nginx,要么毕竟这不是问题。

该网站现在正在开展工作,但这是我对原因和解决方案并没有令人满意的理解的情况之一,所以如果任何人都可以证实这一假设或指出其他事情,我很乐意提供意见。