Articles of django

设置nginx服务django和WordPress的博客作为子目录

upstream django { server unix:///home/ubuntu/web/www.mysite.com/uwsgi-tutorial/mysite/mysite.sock; # for a file socket } server { listen 80; server_name mysite.com www.mysite.com; charset utf-8; client_max_body_size 75M; # adjust to taste #——–PHP PART ———————– location /blog { alias /var/www; try_files $uri =404; index index.php index.html; } location ~ /blog/.+\.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/$fastcgi_script_name; } […]

从nginx连接到gunicorn_django时,连接被拒绝

我试图让升级后的服务器恢复在线状态,我不能再让Nginx直接调用Gunicorn了 – 我发送给网站的每个请求都会返回一个502 Bad Gateway 。 我在端口8001上运行gunicorn_django (从ps aux | grep gunicorn可以看到 – 两个worker的命令的参数是-b 0.0.0.0:8001 。我的Nginxconfiguration在我的唯一configurationsites-enabled : upstream django_test { server 127.0.0.1:8001; } …所以它应该是要求那里。 自升级以来,这个configuration文件没有任何改变。 当我在浏览器中访问mysite.com/robots.txt时,会返回我在sites-enabled了sites-enabledconfiguration中定义的robots.txt ,因此文件肯定会被加载。 此外,当我从服务器运行curl 127.0.0.1我仍然得到502 bad gateway 。 有谁知道这里会发生什么?

宕机前的错误消息:posix_memalign(16,4096)失败(12:无法分配内存)

我有一台运行在Gunicorn和Nginx之上的Django服务器,昨天晚上我经历了一小段时间的停机。 重新启动Nginx和Gunicorn后,服务器恢复正常,但我无法弄清楚是什么导致了中断。 检查日志概述了问题发生的地方:首先,大约有100行: 2014/03/04 15:48:47 [emerg] 21790#0: *19536658 posix_memalign(16, 4096) failed (12: Cannot allocate memory), client: xx.xx.xx.xx, server: www.mysite.com, request: "GET /static/images/loading.gif HTTP/1.1", host: "www.mysite.com" 然后,实际的错误来了。 这其中约有300个: 2014/03/04 15:49:04 [error] 21790#0: *19532341 connect() failed (110: Connection timed out) while connecting to upstream, client: xx.xx.xx.xx, server: www.mysite.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8081/", host: "www.mysite.com" …和其中约100个: […]

如何从手机访问Apache虚拟主机?

我正在开发一个使用Django的移动Web应用程序。 目前我可以像这样启动Django开发服务器: python ./manage.py runserver <my-ip>:8000 当我这样做的时候,我会在我的Mac上看到一个popup窗口, Do you want the application "python" to accept incoming network connections? 如果我点击允许button,然后inputURI“:8000”我可以从我的手机访问网站。 然而,他们是我希望在手机上查看纯HTML页面的时代。 为此,我创build了映射到我的/ www目录的Apache虚拟主机调用“localdev”: # /etc/apache2/httpd.conf … DocumentRoot "/www" … <Directory "/www"> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny Allow from all </Directory> … Include /private/etc/apache2/extra/httpd-vhosts.conf # /etc/apache2/extra/httpd-vhosts.conf NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot "/www" ServerName localdev […]

Django的wsgi和mod_pagespeed不工作

我在我的服务器上安装了mod_pagespeed,它的工作就像页面标题一样: X-Mod-Pagespeed:1.7.30.5-3847 问题是它没有别的办法。 没有空白或评论删除或任何将是显而易见的。 我怎么能在我的服务器上安装它? 我需要添加什么才能使其工作,我应该编辑哪些文件? 如果我能做到这一点,那么我可以弄清楚其余的事情! 启用网站的网站configuration文件: <VirtualHost *:80> ServerAdmin [email protected] ServerName site.com #ServerAlias www.site.com DocumentRoot /var/www/site.com/html/ ErrorLog /var/www/site.com/logs/error.log CustomLog /var/www/site.com/logs/access.log combined WSGIScriptAlias / /var/www/site.com/django/site.com/django.wsgi Alias /static/ /var/www/site.com/html/static/ <Location "/static/"> Options -Indexes </Location> Alias /media/ /var/www/django/contrib/admin/media/ </VirtualHost> WSGI文件: import os, sys sys.stdout = sys.stderr sys.path.append('/var/www/site.com/django') sys.path.append('/var/www/site.com/django/sitename') os.environ['DJANGO_SETTINGS_MODULE'] = 'sitename.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() […]

为什么我看到apache的404而不是Django的自定义404?

在我的本地django runserver上,我创build了一个自定义templates/404.html ,这个工作没有问题。 但是在使用apache进行生产时,这个自定义的404.html不再显示(即使DEBUG=False )。 我只是得到一个白页 Not Found The requested URL /blahblah was not found on this server. 我不相信这不是Django默认,而是与Apache有关。 我如何告诉Apache让django处理404s?

django WSGI API需要Webserver吗?

我的应用程序只是一个用django编写的REST API。 没有静态内容或html页面。 在设置我们的生产环境时,我们计划使用amazon ELB(负载均衡器)来平衡运行django和uWSGI的许多EC2实例之间的请求。 有了这个设置,我们是否需要(或想)使用像nginx这样的web服务器来处理接受的http请求并将它们传递给uWSGUI? 什么好处(如果有的话),这将提供我们只是在networking服务器上运行uWSGI并让它直接从负载均衡器接受HTTP请求? 谢谢!

API和主页面作为两个独立的进程

情况 我为我的移动应用程序创build了一个REST API,现在我想创build一个网站。 API到目前为止非常简单,只是为了“获取内容列表”,“更新数据库中的某个字段”等几个请求。但现在,我想创build一个网站,当然会使用相同的数据库。 我不认为这个API将在网站项目中有用。 题 把API和网站分开保存,在两个不同的实例上更好一些,还是最好把它合并起来? 例如, api.example.com上的API地址为127.0.0.1:8001网站地址为127.0.0.1:8002 ,当然还有两个不同的nginx服务器configuration(如果仍然存在不知道我的意思是:P)? 或者在处理请求方面的performance并不重要,最好是通过链接example.com/api/…完成一个项目。

“在osqa上导入中间件时出错”

我使用下面的教程在Ubuntu 14.0.4上安装了postgresql的osqa作为后端 http://wiki.osqa.net/display/docs/ubuntu+12.04,+django+1.3,+mod_wsgi,+virtual_env,+postgresql 要求创build一个虚拟环境。 我做了同样的,得到500服务器错误。 因此,我在settings_local.py中设置了debug = True,并在显示mod_wsgi错误的apache错误日志文件中出现以下错误。 [Mon Nov 24 11:26:33.823663 2014] [:error] [pid 6389:tid 3034110784] [remote 192.168.227.129:15031] mod_wsgi (pid=6389): Exception occurred processing WSGI script '/srv/osqa.1/osqa/osqa.wsgi'. [Mon Nov 24 11:26:33.823844 2014] [:error] [pid 6389:tid 3034110784] [remote 192.168.227.129:15031] Traceback (most recent call last): [Mon Nov 24 11:26:33.823882 2014] [:error] [pid 6389:tid 3034110784] [remote 192.168.227.129:15031] File […]

Ubuntu升级破解了django mod_wsgi

我在这里敲我的头,似乎无法在任何地方find答案。 我的服务器正在运行Ubuntu 14.04。 我使用Apache和mod_wsgi运行几个Django站点今天更新后,网站将无法正常工作。 我可以看到,libapache2-mod-wsgi:amd64(3.4-4ubuntu2.1.14.04.1,3.4-4ubuntu2.1.14.04.2)是更新之一 这个错误出现在apache错误日志中 mod_wsgi (pid=6624): Failure to configure the daemon process correctly and process left in unspecified state. Restarting daemon process after delay. 虽然这个出现在一个特定的Django应用程序日志 Fatal Python error: PyEval_AcquireThread: NULL new thread state <…> Script timed out before returning headers: wsgi.py 我不记得我是否使用pip安装mod_wsgi。 任何指针都会很棒。