I'm trying to set up a production server which consist of django + uwsgi + ngnix . The tutorial i'm following is located here http://www.panta.info/blog/3/how-to-install-and-configure-nginx-uwsgi-and-django-on-ubuntu.html
我正在尝试建立一个由django + uwsgi + ngnix组成的生产服务器。我正在关注的教程位于http://www.panta.info/blog/3/how-to-install-and-configure-nginx-uwsgi-and-django-on-ubuntu.html
The production server is working because I can see the admin page when debug is on but when I turn debug off . It displays the Server Error (500) again . I don't know what to do . Ngnix should be serving the django request . I'm clueless right now , Can someone kindly help me please.
生产服务器正在运行,因为我可以在调试打开时看到管理页面,但是当我关闭调试时。它再次显示服务器错误(500)。我不知道该怎么办 。 Ngnix应该服务于django请求。我现在很无能为力,请有人帮助我。
my /etc/nginx/sites-available/mysite.com
server {
listen 80;
server_name mysite.com www.mysite.com;
access_log /var/log/nginx/mysite.com_access.log;
error_log /var/log/nginx/mysite.com_error.log;
location / {
uwsgi_pass unix:///tmp/mysite.com.sock;
include uwsgi_params;
}
location /media/ {
alias /home/projects/mysite/media/;
}
location /static/ {
alias /home/projects/mysite/static/;
}
}
my /etc/uwsgi/apps-available/mysite.com.ini
[uwsgi]
vhost = true
plugins = python
socket = /tmp/mysite.com.sock
master = true
enable-threads = true
processes = 2
wsgi-file = /home/projects/mysite/mysite/wsgi.py
virtualenv = /home/projects/venv
chdir = /home/projects/mysite
touch-reload = /home/projects/mysite/reload
my settings.py
root@localhost:~# cat /home/projects/mysite/mysite/settings.py
# Django settings for mysite project.
DEBUG = False
TEMPLATE_DEBUG = DEBUG
min/css/base.css" failed (2: No such file or directory), client: 160.19.332.22, server: mysite.com, request: "GET /static/admin/css/base.css HTTP/1.1", host: "160.19.332.22"
2013/06/17 14:33:39 [error] 8346#0: *13 open() "/home/projects/mysite/static/admin/css/login.css" failed (2: No such file or directory), client: 160.19.332.22, server: mysite.com, request: "GET /static/admin/css/login.css HTTP/1.1", host: "174.200.14.200"
2013/06/17 14:33:39 [error] 8346#0: *14 open() "/home/projects/mysite/static/admin/css/base.css" failed (2: No such file or directory), client: 160.19.332.22, server: mysite.com, request: "GET /static/admin/css/base.css HTTP/1.1", host: "174.200.14.2007", referrer: "http://174.200.14.200/admin/"
2013/06/17 14:33:39 [error] 8346#0: *15 open() "/home/projects/mysite/static/admin/css/login.css" failed (2: No such file or directory), client: 160.19.332.22, server: mysite.com, request: "GET /static/admin/css/login.css HTTP/1.1", host: "174.200.14.200", referrer: "http://174.200.14.200/admin/"
1 个解决方案
#1
18
I think it's your ALLOWED_HOSTS
setting (new in Django 1.5)
我认为这是你的ALLOWED_HOSTS设置(Django 1.5中的新功能)
Try the following in your settings.py
在settings.py中尝试以下操作
ALLOWED_HOSTS = ['*']
This will allow everything to connect until you get your domain name sorted.
这将允许所有内容连接,直到您对域名进行排序。
It's worth saying that when you do get a domain name sorted make sure you update this value (list of allowed domain names). As the documentation for ALLOWED_HOSTS
states:
值得一提的是,当您确实获得域名排序时,请确保更新此值(允许的域名列表)。正如ALLOWED_HOSTS的文档所述:
This is a security measure to prevent an attacker from poisoning caches and password reset emails with links to malicious hosts by submitting requests with a fake HTTP Host header, which is possible even under many seemingly-safe webserver configurations.
这是一种安全措施,可以通过使用伪造的HTTP主机标头提交请求来防止攻击者通过链接到恶意主机来中毒缓存和密码重置电子邮件,即使在许多看似安全的Web服务器配置下也是如此。
Also (a little aside) - I don't know if you have a different setup for your django settings per environment but this is what I do:
另外(稍微一点) - 我不知道你的每个环境的django设置是否有不同的设置,但这就是我所做的:
At the end of your settings.py
include:
在settings.py结束时包括:
try:
from local_settings import *
except ImportError:
pass
Then in the same directory as settings.py
create a local_settings.py
file (and a __init__.py
file if using a different structure than the initial template) and set your settings per environment there. Also exclude local_settings.py
from your version control system.
然后在与settings.py相同的目录中创建一个local_settings.py文件(如果使用与初始模板不同的结构,则创建一个__init__.py文件)并在那里设置每个环境的设置。还要从版本控制系统中排除local_settings.py。
e.g. I have DEBUG=False
in my settings.py
(for a secure default) but can override with DEBUG=True
in my development local settings.
例如我的settings.py中有DEBUG = False(安全默认值)但在我的开发本地设置中可以使用DEBUG = True覆盖。
I also keep all my database info in my local settings file so it's not in version control.
我还将所有数据库信息保存在我的本地设置文件中,因此它不受版本控制。
Just a little info if you didn't know it already :-)
如果你不知道它只是一点信息:-)
#1
18
I think it's your ALLOWED_HOSTS
setting (new in Django 1.5)
我认为这是你的ALLOWED_HOSTS设置(Django 1.5中的新功能)
Try the following in your settings.py
在settings.py中尝试以下操作
ALLOWED_HOSTS = ['*']
This will allow everything to connect until you get your domain name sorted.
这将允许所有内容连接,直到您对域名进行排序。
It's worth saying that when you do get a domain name sorted make sure you update this value (list of allowed domain names). As the documentation for ALLOWED_HOSTS
states:
值得一提的是,当您确实获得域名排序时,请确保更新此值(允许的域名列表)。正如ALLOWED_HOSTS的文档所述:
This is a security measure to prevent an attacker from poisoning caches and password reset emails with links to malicious hosts by submitting requests with a fake HTTP Host header, which is possible even under many seemingly-safe webserver configurations.
这是一种安全措施,可以通过使用伪造的HTTP主机标头提交请求来防止攻击者通过链接到恶意主机来中毒缓存和密码重置电子邮件,即使在许多看似安全的Web服务器配置下也是如此。
Also (a little aside) - I don't know if you have a different setup for your django settings per environment but this is what I do:
另外(稍微一点) - 我不知道你的每个环境的django设置是否有不同的设置,但这就是我所做的:
At the end of your settings.py
include:
在settings.py结束时包括:
try:
from local_settings import *
except ImportError:
pass
Then in the same directory as settings.py
create a local_settings.py
file (and a __init__.py
file if using a different structure than the initial template) and set your settings per environment there. Also exclude local_settings.py
from your version control system.
然后在与settings.py相同的目录中创建一个local_settings.py文件(如果使用与初始模板不同的结构,则创建一个__init__.py文件)并在那里设置每个环境的设置。还要从版本控制系统中排除local_settings.py。
e.g. I have DEBUG=False
in my settings.py
(for a secure default) but can override with DEBUG=True
in my development local settings.
例如我的settings.py中有DEBUG = False(安全默认值)但在我的开发本地设置中可以使用DEBUG = True覆盖。
I also keep all my database info in my local settings file so it's not in version control.
我还将所有数据库信息保存在我的本地设置文件中,因此它不受版本控制。
Just a little info if you didn't know it already :-)
如果你不知道它只是一点信息:-)