Centos + nginx + uwsgi + Python multi-site environment setup, centosng.pdf
Preface
The first project of the new company, the server end intends to use python as a restful api. Therefore, we need to build the nginx + fastcgi + python Development Environment on Centos. However, many comments on the Internet that uwsgi has many advantages over fastcgi. We recommend uwsgi instead of fastcgi. For details, see: http://sunxiunan.com /? P = 1778. Therefore, we need to build a technical Combination such as nginx + uwsgi + python.
Question
Start building the environment. Bytes. When testing in Step 8, the browser displays "Internal server error". It can be determined that the connection between uwsgi and django is faulty. It is estimated that the uwsgi configuration is faulty. So I found another technical post to solve my problem. For details, see http://django-china.cn/topic/101 /. This article splits the building process to help you understand the building process. However, when I connect django and uwsgi After configuring django, a problem occurs. The background displays:
Django. core. exceptions. AppRegistryNotReady: Models aren't loaded yet. Later, I found the cause on the Internet. For django1.4 and django1.5, wsgi. py is:
Import OS
Import sys
From django. core. handlers. wsgi import WSGIHandler
OS. environ ['django _ SETTINGS_MODULE '] = 'myapp. setting'
Application = WSGIHandler ()
However, when django1.7 is used
import os
import sys
from django.core.wsgi import get_wsgi_application
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
application = get_wsgi_application()
Ah, this is really a pitfall. After the problem is solved, django and uwsgi are successfully connected. All requests are passed to the django program through uwsgi for processing. Continue to follow the steps in this article and encounter problems again. When you start the uwsgi service and run the uwsgi-x djangochina_socket.xml command, the following message is displayed: uwsgi: invalid option -- 'x'. Find the answer: this problem occurs because libxml2 library is missing when uwsgi is compiled. You should install the library before compiling. Otherwise, xml support will be missing. Note that libxm must be installed before uwsgi; otherwise, it is invalid. Because I have already installed uwsgi, You Need To uninstall uwsgi first and run pip uninstall uwsgi. This shows the advantages of the first blog post. It is very convenient to use pip to install and uninstall the program. Next, yum install libxml * to install the libxml2 library.
OK. Finally, all the problems are solved. When you access http: // 127.0.0.1/admin in the browser, you will be able to see the django background management logon interface!