Django开发笔记(一)

购得云服务器一台作为生产环境,系统为CentOS 7。

下面配置生产环境

SSH登录。


yum install分别安装nginx,httpd(apache),python-devel,httpd-devel。


安装python包管理工具pip:下载get-pip.py,运行python get-pip.py


pip安装django


安装mod_wsgi:下载mod_wsgi压缩包,解压缩,用find命令找到apxs及python路径,依次执行:

./configure --with-apxs=/usr/local/apache/bin/apxs --with-python=/usr/local/bin/python
make
make install

配置apache(/etc/httpd/conf/httpd.conf)

LoadModule wsgi_module /usr/lib64/httpd/modules/mod_wsgi.so

DocumentRoot "/var/www/mysite.com"

WSGIScriptAlias / /var/www/mysite.com/mysite/wsgi.py
WSGIPythonPath /var/www/mysite.com


  
    Require all granted
  


配置nginx(/etc/nginx/nginx.conf and /etc/nginx/sites-enabled/mysite.conf)

include /etc/nginx/sites-enabled/*.conf;

server {
  listen 80:
  server_name mysite.com www.mysite.com;
  location / {
    proxy_set_header X-Read-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $host;
    proxy_pass http://127.0.0.1:apache_port
  }

  error_page 500 502 503 504 /50x.html;

  location = /50x.html {
    root html;
  }

  location ~* ^.+\.(jpg|jpeg|gif|png|css|zip|pdf|tex|js|flv|swf|html|htm)$
  {
    root /var/www/mysite;
  }
}

安装mysql(mariadb)

yum install mariadb mariadb-server
service mariadb start
mysql_secure_installation

配置mysql字符集

[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci

安装mysqlclient(python connector)

yum install mariadb-devel
pip install mysqlclient

你可能感兴趣的:(Django开发笔记(一))