將Django項目部署在LAMP/LNMP平臺上,用於真正的生產環境,須要注意一下兩點:
python
數據庫編碼mysql
1. 數據庫建立 CREATE DATABASE `test` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; 2. 數據庫設置 /etc/my.cnf [client] default-character-set=utf8 [mysqld] character-set-server= utf8 default-character-set= utf8 init_connect='SET NAMES utf8' [mysql] default-character-set=utf8 # mysql 查看數據庫信息以下 mysql > use test mysql > status +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 3. 項目設置 djangoproject/setting.py設置以下 TIME_ZONE = 'Asia/Shanghai' LANGUAGE_CODE = 'zh-cn' DEFAULT_CHARSET = 'utf-8' TEST_CHARSET = 'utf-8' TEST_COLLATION = 'utf-8' DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'test2', 'USER': 'root', 'PASSWORD': '', 'HOST': '172.16.20.64', 'PORT': '3306', 'TEST_CHARSET': 'utf-8', 'TEST_COLLATION': 'utf-8', 'DEFAULT_CHARSET': 'utf-8', } }
2. UWSGI反代nginx
項目中使用到了Django,MySQLdb,固然還有apache反代django時須要的uWSGIsql
還有兩個依賴庫 python-devel以及mysql-devel數據庫
1. 安裝依賴庫 yum -y install python-devel mysql-devel 2. 安裝apache uWSGI模塊(若是使用nginx這步能夠省略) wget --no-check-certificate # 編譯uWSGI.c文件 /apache安裝目錄/bin/apxs -i -c mod_uwsgi.c 3. 配置httpd.conf # 這些東西加在那裏瀏覽一遍conf文件你就知道 :) LoadModule uwsgi_module modules/mod_uwsgi.so <Location "/"> SetHandler uwsgi-handler uWSGISocket 127.0.0.1:8080 # 這是指定反代地址 </Location> <Location "/static"> SetHandler none # 這是定義django靜態文件處理方式 </Location> # 靜態文件alias Alias /static /data01/httpd/htdocs/thirddjango/static 4. 在htdocs目錄下設置UWSGI.INI [uwsgi] chdir = /data01/httpd/htdocs/thirddjango # httpd的發佈目錄 module = thirddjango.wsgi # django項目中的wsgi env DJANGO_SETTINGS_MODULE=thirddjango.settings # 項目settings文件 master = true processes = 2 socket = 127.0.0.1:8080 # uwsgi工做端口 max-requests = 100 vacuum = true daemonize = /data01/httpd/logs/django.log # django日誌文件位置 5. 安裝Django,MySQLdb模塊 # 安裝easy_install工具,便於安裝以上的模塊 wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py python ez_setup.py install easy_install django easy_install "MySQL-python==1.2.3"