ubuntu14.04+Django+Nginx+uWSGI
来源:互联网 发布:雅思水平测试软件 编辑:程序博客网 时间:2024/05/05 22:27
一、Django官网:https://www.djangoproject.com/download/
版本:Django-1.9.9
tar zxvf /home/lj/Django-1.9.9.tar.gz -C /usr/local # 解压下载包cd /usr/local/Django-1.9.9 # 进入 Django 目录python setup.py install # 执行安装命令
如果报错:
ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory解决:
[root@iZ28cumdzmgZ muahao03]# find / -name libmysqlclient.so.18/usr/local/mysql/lib/libmysqlclient.so.18 [root@iZ28cumdzmgZ muahao03]# ls -ld /usr/lib/dr-xr-xr-x. 50 root root 36864 Dec 23 03:40 /usr/lib/ [root@iZ28cumdzmgZ muahao03]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18 [root@iZ28cumdzmgZ muahao03]# pythonPython 2.7.9 (default, Dec 19 2014, 18:09:06) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import MySQLdb >>>exit()
二、离线安装uwsgi
版本:uwsgi-2.0.13.1.tar.gz
1、安装:
sudo tar -zxvf /home/lj/uwsgi-2.0.13.1.tar.gz -C /usr/localcd /usr/local/uwsgi-2.0.13.1sudo make -j 8或者使用python编译python uwsgiconfig.py --buildcp /usr/local/uwsgi-2.0.13.1/uwsgi /usr/sbin/
2、测试启动:
cd /usr/local/uwsgi-2.0.13.1/uwsgi --http :9090 --wsgi-file /home/lj/mytest.py
1、在项目的根目录下新建一个django_wsgi.py
#!/usr/bin/env python# coding: utf-8import osfrom django.core.wsgi import get_wsgi_applicationos.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")application = get_wsgi_application()2、测试启动
sudo /usr/local/uwsgi-2.0.13.1/uwsgi --http :9090 --chdir /home/lj/myproject --module django_wsgi
四、安装nginx
1、安装zlib
版本:zlib-1.2.8.tar.gz
sudo tar -zxvf /home/lj/zlib-1.2.8.tar.gz -C /usr/localcd /usr/local/zlib-1.2.8/sudo ./configuresudo makesudo make install2、安装pcr
版本:pcre-8.38.zip
(1)、依赖包,安装顺序如下:
sudo dpkg -i libstdc++-4.8-dev_4.8.4-2ubuntu1-14.04.3_amd64.debsudo dpkg -i g++-4.8_4.8.4-2ubuntu1-14.04.3_amd64.deb sudo dpkg -i g++_4.8.2-1ubuntu6_amd64.deb sudo dpkg -i gcc_4.8.2-1ubuntu6_amd64.debsudo dpkg -i libdpkg-perl_1.17.5ubuntu5.6_all.deb sudo dpkg -i dpkg-dev_1.17.5ubuntu5.6_all.debsudo dpkg -i build-essential_11.6ubuntu6_amd64.deb(2)、安装pcre
unzip -d /usr/local /home/lj/pcre-8.38.zipcd /usr/local/pcre-8.38/sudo ./configuresudo makesudo make install3、安装nginx
版本:nginx-1.8.1.tar.gz
sudo tar -zxvf /home/lj/nginx-1.8.1.tar.gz -C /usr/localcd /usr/local/nginx-1.8.1sudo ./configuresudo makesudo make install
如果报错:
ImportError: libpcre.so.1: cannot open shared object file: No such file or directory解决:
root@ubuntu:/usr/local/nginx/sbin# sudo ./nginx./nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directoryroot@ubuntu:/usr/local/nginx/sbin# find / -name libpcre.so.1/usr/local/lib/libpcre.so.1/usr/local/pcre-8.38/.libs/libpcre.so.1root@ubuntu:/usr/local/nginx/sbin# ls -ld /usr/lib/drwxr-xr-x 149 root root 20480 Sep 18 01:12 /usr/lib/root@ubuntu:/usr/local/nginx/sbin# ln -s /usr/local/pcre-8.38/.libs/libpcre.so.1 /usr/lib/libpcre.so.1root@ubuntu:/usr/local/nginx/sbin# sudo ./nginx
(1)、nginx开机自动启动
参考:http://www.cnblogs.com/xuyuan77/p/5526639.html
vim /etc/init.d/nginx
输入:
#! /bin/bash# Description: Startup script for webserver on CentOS. cp it in /etc/init.d and# chkconfig --add nginx && chkconfig nginx on# then you can use server command control nginx## chkconfig: 2345 08 99# description: Starts, stops nginxset -ePATH=$PATH:/usr/local/nginx/sbin/DESC="nginx daemon"NAME=nginxDAEMON=/usr/local/nginx/sbin/$NAMECONFIGFILE=/usr/local/nginx/conf/nginx.confPIDFILE=/var/run/nginx.pidSCRIPTNAME=/etc/init.d/$NAME# Gracefully exit if the package has been removed.test -x $DAEMON || exit 0d_start() {$DAEMON -c $CONFIGFILE || echo -n " already running"}d_stop() {kill -QUIT `cat $PIDFILE` || echo -n " not running"}d_reload() {kill -HUP `cat $PIDFILE` || echo -n " can't reload"}case "$1" instart)echo -n "Starting $DESC: $NAME"d_startecho ".";;stop)echo -n "Stopping $DESC: $NAME"d_stopecho ".";;reload)echo -n "Reloading $DESC configuration..."d_reloadecho "reloaded.";;restart)echo -n "Restarting $DESC: $NAME"d_stopsleep 1d_startecho ".";;*)echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2exit 3;;esacexit 0将nginx添加到自启动服务中并启动:
chmod 700 /etc/init.d/nginxsudo sysv-rc-conf nginx on(2)、再配置每天自动切割nginx日志脚本:
vi /usr/local/nginx/sbin/cut_nginx_log.sh输入:
#!/bin/bash # This script run at 00:00 # The Nginx logs path logs_path="/usr/local/nginx/logs/" logs_bak_path="/data/logs/nginx/" mkdir -p ${logs_bak_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/ cp ${logs_path}access.log ${logs_bak_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log rm -rf ${logs_path}*.log kill -USR1 `cat /var/run/nginx.pid`
(3)、常用命令:
/etc/init.d/nginx start/etc/init.d/nginx stopkillall nginx
五、nginx+django+uwsgi(说明:多个站点需要配置多个uwsgiXXXX.ini和/etc/init.d/uwsgixxxx以及nginx.conf下的多个server)
1、在项目根目录下新建uwsgi9006.ini文件(与django_wsgi相同目录)
#此名字可以随意取,加上端口号,容易区分[uwsgi]socket = :9006chdir= /home/lj/myproject# Django s wsgi filemodule= django_wsgi#日志文件daemonize = /home/lj/myproject/uwsgi9006.log#pid文件,用于下面的脚本启动、停止该进程pidfile = /var/run/uwsgi9006.pid# 主进程master = true#多站模式vhost = true#多站模式时不设置入口模块和文件no-stie = true#子进程数workers = 2reload-mercy = 10#退出、重启时清理文件vacuum = truemax-requests = 1000limit-as = 512buffer-sizi = 30000
启动uwsgi
uwsgi --ini /home/lj/myproject/uwsgi9006.ini
2、uwsgi设置开机启动,已测试端口9006为列子
参考:http://www.tuicool.com/articles/qEVrYn 和 http://www.linuxdiyf.com/linux/11461.html
vim /etc/init.d/uwsgi9006输入:
#! /bin/sh# chkconfig: 2345 55 25# Description: Startup script for uwsgi webserver on Debian. Place in /etc/init.d and# run 'update-rc.d -f uwsgi defaults', or use the appropriate command on your# distro. For CentOS/RedHat run: 'chkconfig --add uwsgi' ### BEGIN INIT INFO# Provides: uwsgi# Required-Start:$all# Required-Stop: $all# Default-Start: 2 3 4 5# Default-Stop: 0 1 6# Short-Description: starts the uwsgi web server# Description: starts uwsgi using start-stop-daemon### END INIT INFO # Author: licess# website: http://lnmp.orgPATH=$PATH:/usr/local/uwsgi-2.0.13.1/ DESC="uwsgi daemon" NAME=uwsgi9006 DAEMON=/usr/local/uwsgi-2.0.13.1/uwsgi CONFIGFILE=/home/lj/myproject/$NAME.iniPIDFILE=/var/run/$NAME.pidSCRIPTNAME=/etc/init.d/$NAME set -e[ -x "$DAEMON" ] || exit 0 do_start() {$DAEMON $CONFIGFILE || echo -n "uwsgi already running"} do_stop() {$DAEMON --stop $PIDFILE || echo -n "uwsgi not running"rm -f $PIDFILEecho "$DAEMON STOPED."} do_reload() {$DAEMON --reload $PIDFILE || echo -n "uwsgi can't reload"} do_status() {ps aux|grep $DAEMON} case "$1" instatus)echo -en "Status $NAME: \n"do_status;;start)echo -en "Starting $NAME: \n"do_start;;stop)echo -en "Stopping $NAME: \n"do_stop;;reload|graceful)echo -en "Reloading $NAME: \n"do_reload;;*)echo "Usage: $SCRIPTNAME {start|stop|reload}" >&2exit 3;;esac exit 0
将uwsgi添加到自启动服务中并启动:
chmod 700 /etc/init.d/uwsgi9006sudo sysv-rc-conf uwsgi9006 on重启uwsgi9006
killall uwsgi/etc/init.d/uwsgi9006 stop/etc/init.d/uwsgi9006 start
gedit /usr/local/nginx/conf/nginx.conf输入:
#user root;worker_processes 1;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;pid /var/run/nginx.pid;events { use epoll; worker_connections 65535;}http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on;server { listen 8006; server_name 192.168.224.135; ##对外访问的IP和端口号 access_log /usr/local/nginx/logs/access.log; error_log /usr/local/nginx/logs/error.log; #charset koi8-r; #access_log logs/host.access.log main; location / { include uwsgi_params; uwsgi_pass 192.168.224.135:9006; uwsgi_read_timeout 300; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # #error_page 500 502 503 504 /registration/500.html; #location = /registration/500.html { # root html; #} location /static/ { alias /home/lj/myproject/static/; index index.html index.htm; } location /media/ { alias /home/lj/myproject/media/; } }}
重启nginx
service nginx stopservice nginx start
0 0
- ubuntu14.04+Django+Nginx+uWSGI
- ubuntu12.04+nginx+uWsgi+django
- django + nginx + uwsgi
- Nginx + uwsgi + django 配置
- Django+Nginx+uwsgi部署
- nginx+uwsgi+django
- nginx uwsgi django部署
- nginx uwsgi 部署django
- nginx+uwsgi+django
- django nginx+uwsgi部署
- Nginx + uWSGI + Django 配置
- nginx+django+uwsgi
- Centos+nginx+uwsgi+django
- nginx + django + uwsgi 配置
- django+uWSGI+Nginx配置
- Django+uWsgi+nginx部署
- Nginx+uWSGI+Django部署
- django uwsgi nginx
- 使用clonedigger来检查python中的重复代码
- Leetcode_15
- 我的Java之路一:有志者,事竟成!
- Android源码设计模式解析与实战——面向对象六大原则(一)
- LCA在线算法(RMQ st算法的结合)
- ubuntu14.04+Django+Nginx+uWSGI
- ubuntu firefox 切换标签页快捷键
- linux:wc命令(word count)
- 版本更新(xml)方法提出去了
- 【转】百度首页html练习
- Spring4深入理解01----Bean配置(依赖注入和控制反转的区别)
- android:debuggable属性
- 329LongestIncreasingPathinaMatrix
- Hadoop 是什么