7

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

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.

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/"
4

2 回答 2

18

我认为这是您的ALLOWED_HOSTS设置(Django 1.5 中的新功能)

在你的尝试以下settings.py

ALLOWED_HOSTS = ['*']

这将允许一切连接,直到您对域名进行排序。

值得一提的是,当您对域名进行排序时,请确保更新此值(允许的域名列表)。作为ALLOWED_HOSTS状态的文档:

这是一种安全措施,可防止攻击者通过提交带有虚假 HTTP Host 标头的请求来毒化带有指向恶意主机链接的缓存和密码重置电子邮件,即使在许多看似安全的 Web 服务器配置下也是可能的。

另外(有点偏题)-我不知道您是否对每个环境的 django 设置进行了不同的设置,但这就是我所做的:

在您的最后settings.py包括:

try:
    from local_settings import *
except ImportError:
    pass

settings.py然后在与创建local_settings.py文件相同的目录中(__init__.py如果使用与初始模板不同的结构,则为文件)并在那里设置每个环境的设置。local_settings.py还要从您的版本控制系统中排除。

例如,我DEBUG=False在我的(用于安全默认值)中,但可以在我的开发本地设置settings.py中覆盖。DEBUG=True

我还将所有数据库信息保存在我的本地设置文件中,因此它不在版本控制中。

如果您还不知道,请提供一些信息:-)

于 2013-06-17T15:51:51.347 回答
1

我有同样的问题,但在我的情况下,它STATICFILES_STORAGE被错误地设置为:

STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'

这个问题已经有一个公认的答案,但我会留下这个,以防有人遇到同样的情况。对于相同的错误,您还可以看到类似的答案。

于 2019-03-02T05:39:27.190 回答