Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2016-06-07 15:25:57
Original
1392 people have browsed it

So,开始之前你需要什么? 关于openwrt OpenWrt的被描述为一个嵌入式设备的Linux发行版,而不是试图建立一个单一的,静态的固件,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盘上。

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
Copy after login

#修改etc/config/fstab文件如下:
 
echo option force_space >> /etc/opkg.conf
reboot
Copy after login


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

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

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


安装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
Copy after login
安装这几个包
opkg install libffi*.ipk
opkg install python-mini*.ipk
opkg install python_2*.ipk
Copy after login


下载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
Copy after login

安装Pip
easy_install pip 
Copy after login

安装django
pip install django
Copy after login


创建一个django项目,比如Onrt

django-admin.py startproject Onrt
Copy after login
 

让路由器咆哮

(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
Copy after login

opkg install nginx
opkg install fastcgi
Copy after login

测试下nginx

/etc/init.d/nginx start
Copy after login

遇到错误,修改端口。

修改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
        #    }
        #}
    }
}
Copy after login

运行fastcgi

python /root/Onrt/manage.py runfcgi host=127.0.0.1 port=1259;
Copy after login

记得保持端口一致


大功告成:Welcome to Django

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



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template