Blog

Blog

PHODAL

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

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

关于openwrt

OpenWrt的被描述为一个嵌入式设备的Linux发行版,而不是试图建立一个单一的,静态的固件,OpenWrt的包管理提供了一个完全可写的文件系统,从应用程序供应商提供的选择和配置,并允许您自定义的设备,以适应任何应用程序通过使用包。对于开发人员,OpenWrt的是框架来构建应用程序,而无需建立一个完整的固件左右;对于用户来说,这意味着完全定制的能力,从来没有预想的方式使用该设备。
  1. 装有Openwrt的路由器              一个      
  2. 使你的路由器能上网

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

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

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

 

  1. opkg update  
  2. opkg install kmod-usb-ohci kmod-usb2 kmod-fs-ext3  
  3. opkg install kmod-usb-storage  
  4. reboot  
  5. mount /dev/sda1 /mnt  
  6. mkdir /tmp/root  
  7. mount -o bind / /tmp/root  
  8. cp /tmp/root/* /mnt -a  
  9. umount /tmp/root  
  10. umount /mnt  
  11. echo Booted from internal rom >> /etc/banner  
  12. opkg update  
  13. opkg install block-extroot  


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

 

 

  1.    
  2. echo option force_space >> /etc/opkg.conf  
  3. reboot  



 

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

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

 

安装Python以及Django

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

 

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

安装这几个包

  1. opkg install libffi*.ipk  
  2. opkg install python-mini*.ipk  
  3. 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

 

  1. sh setuptools-0.6c11-py2.6.egg  


安装Pip

 

 

  1. easy_install pip   


安装django

 

 

  1. pip install django  

 

 

创建一个django项目,比如Onrt

 

  1. django-admin.py startproject Onrt  

 

 

 

让路由器咆哮

(powered by Phodal.com)
安装sqlite以及lighttpd,如果不能直接安装请使用wget 
  1. opkg install lighttpd  
  2. opkg install libsqlite2  
  3. opkg install libsqlite3  
  4. opkg install lighttpd-mod-access  
  5. opkg install lighttpd-mod-alias  
  6. opkg install lighttpd-mod-cgi  
  7. opkg install lighttpd-mod-fastcgi  
  8. opkg install lighttpd-mod-rewrite  
  9. opkg install lighttpd-mod-redirect  
  10. opkg install sqlite2-cli  

  1. opkg install nginx  
  2. opkg install fastcgi  

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

遇到错误,修改端口。
修改nginx.conf。位于/etc/nginx/nginx.conf
  1. user nobody nogroup;  
  2. worker_processes  1;  
  3.   
  4. error_log  logs/error.log;  
  5. #error_log  logs/error.log  notice;  
  6. #error_log  logs/error.log  info;  
  7.   
  8. events {  
  9.     worker_connections  1024;  
  10. }  
  11.   
  12.   
  13. http {  
  14.     include mime.types;  
  15.     index index.php index.html index.htm;  
  16.     default_type text/html;  
  17.   
  18.     sendfile on;  
  19.     keepalive_timeout 65;  
  20.     gzip on;  
  21.   
  22.     gzip_min_length  1k;  
  23.     gzip_buffers     4 16k;  
  24.     gzip_http_version 1.0;  
  25.     gzip_comp_level 2;  
  26.     gzip_types       text/plain application/x-javascript text/css application/xml;  
  27.     gzip_vary on;  
  28.     server {  
  29.             listen       88;  
  30.             server_name  YOUR_SERVER;  
  31.   
  32.         fastcgi_connect_timeout 300;  
  33.         fastcgi_send_timeout 300;  
  34.         fastcgi_read_timeout 300;  
  35.         fastcgi_buffer_size 32k;  
  36.         fastcgi_buffers 4 32k;  
  37.         fastcgi_busy_buffers_size 32k;  
  38.         fastcgi_temp_file_write_size 32k;  
  39.         client_body_timeout 10;  
  40.         client_header_timeout 10;  
  41.         send_timeout 60;  
  42.         output_buffers 1 32k;  
  43.         postpone_output 1460;  
  44.   
  45.         root   /root/Onrt;  
  46.   
  47.         location /static/ { # STATIC_URL  
  48.             alias /root/Onrt; # STATIC_ROOT  
  49.             expires 30d;  
  50.         }  
  51.   
  52.         location /media/ { # MEDIA_URL  
  53.             alias /root/Onrt; # MEDIA_ROOT  
  54.             expires 30d;  
  55.         }  
  56.   
  57.         location / {  
  58.             include fastcgi_params;  
  59.             fastcgi_pass 127.0.0.1:1259;  
  60.         }  
  61.   
  62.         #location ~ \.php$ {  
  63.         #    fastcgi_index  index.php;  
  64.         #    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;  
  65.         #    include        fastcgi_params;  
  66.         #  
  67.         #    if (-f $request_filename) {  
  68.         #        # Only throw it at PHP-FPM if the file exists (prevents some PHP exploits)  
  69.         #        fastcgi_pass    127.0.0.1:1026;     # The upstream determined above  
  70.         #    }  
  71.         #}  
  72.     }  
  73. }  

运行fastcgi
  1. 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

Engineer, Consultant, Writer, Designer

ThoughtWorks 技术专家

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

开源深度爱好者

出版有《前端架构:从入门到微前端》、《自己动手设计物联网》、《全栈应用开发:精益实践》

联系我: h@phodal.com

微信公众号: 最新技术分享

标签