Blog

Blog

PHODAL

Openwrt,路由器上运行Django,基于DB120

So,开始之前你需要什么?

  1. 装有Openwrt的路由器              一个      
  2. 使你的路由器能上网

所以,你需要买上一个路由器,或者用自带的,至于各种教程就网上找吧。如果不知道Openwrt是什么请谷歌,如果你的路由器不能上网,带有无线的话,试着用connectify共享出你的网络。

(Ps:需要有Linux基础才会各种没有压力,power by Phodal.com)

参考这个贴子:http://www.openwrt.org.cn/bbs/forum.php?mod=viewthread&tid=5983,扩展你的系统到U盘上。

 

opkg update
opkg install kmod-usb-ohci kmod-usb2 kmod-fs-ext3
opkg install kmod-usb-storage
reboot
mount /dev/sda1 /mnt
mkdir /tmp/root
mount -o bind / /tmp/root
cp /tmp/root/* /mnt -a
umount /tmp/root
umount /mnt
echo Booted from internal rom >> /etc/banner
opkg update
opkg install block-extroot


#修改etc/config/fstab文件如下:

 

 

 
echo option force_space >> /etc/opkg.conf
reboot



 

当然了,如果你的路由器带有支持extroot功能的话,直接就能用。如我的

总之是为了保证有足够的空间来安装这些。

 

安装Python以及Django

需要安装libffi,python-mini,python。libffi以及python-mini需要安装在python之前

 

wget -c http://downloads.openwrt.org.cn/backfire/10.03.1/brcm63xx/packages/libffi_3.0.9-1_brcm63xx.ipk
wget -c http://downloads.openwrt.org.cn/backfire/10.03.1/brcm63xx/packages/python-mini_2.6.4-3_brcm63xx.ipk
wget -c http://downloads.openwrt.org.cn/backfire/10.03.1/brcm63xx/packages/python_2.6.4-3_brcm63xx.ipk

安装这几个包

opkg install libffi*.ipk
opkg install python-mini*.ipk
opkg install python_2*.ipk

 

 

下载setuptools

http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c11-py2.6.egg#md5=bfa92100bd772d5a213eedd356d64086

安装easy_install

 

sh setuptools-0.6c11-py2.6.egg


安装Pip

 

 

easy_install pip 


安装django

 

 

pip install django

 

 

创建一个django项目,比如Onrt

 

django-admin.py startproject Onrt

 

 

 

让路由器咆哮

(powered by Phodal.com)
安装sqlite以及lighttpd,如果不能直接安装请使用wget 
opkg install lighttpd
opkg install libsqlite2
opkg install libsqlite3
opkg install lighttpd-mod-access
opkg install lighttpd-mod-alias
opkg install lighttpd-mod-cgi
opkg install lighttpd-mod-fastcgi
opkg install lighttpd-mod-rewrite
opkg install lighttpd-mod-redirect
opkg install sqlite2-cli

opkg install nginx
opkg install fastcgi

测试下nginx
/etc/init.d/nginx start

遇到错误,修改端口。
修改nginx.conf。位于/etc/nginx/nginx.conf
user nobody nogroup;
worker_processes  1;

error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

events {
    worker_connections  1024;
}


http {
    include mime.types;
    index index.php index.html index.htm;
    default_type text/html;

    sendfile on;
    keepalive_timeout 65;
    gzip on;

    gzip_min_length  1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types       text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
    server {
            listen       88;
            server_name  YOUR_SERVER;

        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 32k;
        fastcgi_buffers 4 32k;
        fastcgi_busy_buffers_size 32k;
        fastcgi_temp_file_write_size 32k;
        client_body_timeout 10;
        client_header_timeout 10;
        send_timeout 60;
        output_buffers 1 32k;
        postpone_output 1460;

        root   /root/Onrt;

        location /static/ { # STATIC_URL
            alias /root/Onrt; # STATIC_ROOT
            expires 30d;
        }

        location /media/ { # MEDIA_URL
            alias /root/Onrt; # MEDIA_ROOT
            expires 30d;
        }

        location / {
            include fastcgi_params;
            fastcgi_pass 127.0.0.1:1259;
        }

        #location ~ \.php$ {
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        #    include        fastcgi_params;
        #
        #    if (-f $request_filename) {
        #        # Only throw it at PHP-FPM if the file exists (prevents some PHP exploits)
        #        fastcgi_pass    127.0.0.1:1026;     # The upstream determined above
        #    }
        #}
    }
}

运行fastcgi
python /root/Onrt/manage.py runfcgi host=127.0.0.1 port=1259;

记得保持端口一致
 

大功告成:Welcome to Django


或许您还需要下面的文章:

关于我

Github: @phodal     微博:@phodal     知乎:@phodal    

微信公众号(Phodal)

围观我的Github Idea墙, 也许,你会遇到心仪的项目

QQ技术交流群: 321689806
comment

Feeds

RSS / Atom

最近文章

关于作者

Phodal Huang

Developer, Consultant, Writer, Designer

ThoughtWorks 高级咨询师

工程师 / 咨询师 / 作家 / 设计学徒

开源深度爱好者

出版有《自己动手设计物联网》、《全栈应用开发:精益实践》

联系我: h@phodal.com

微信公众号: 与我沟通

标签