查看: 20053|回复: 0

[教程] 树莓派教程之小型web服务器

[复制链接]
  • TA的每日心情
    奋斗
    2014-7-16 09:10
  • 签到天数: 361 天

    连续签到: 1 天

    [LV.8]以坛为家I

    发表于 2014-2-20 09:18:33 | 显示全部楼层 |阅读模式
    分享到:
    本帖最后由 GY@艳 于 2014-2-20 09:20 编辑

    这次要搭建一个nginx+php+mysql+dnspod动态解析

    有路由器的么直接去路由器管理界面把树莓的mac绑定下,再映射这样会方便很多,不用担心ip变掉。

    首先sudo su获得root权限后操作会方便很多

    apt-get update

    apt-get install nginx php5-fpm php5-cli php5-curl php5-gd php5-mcrypt php5-mysql php5-cgi mysql-server

    安装期间会提示叫你输入数据库密码(这必须要记住..)

    • 环境配置

    在root权限命令行输入命令

    nano /etc/nginx/nginx.conf

    对照修改如下
    开头部分

    user www-data;worker_processes 1;   修改这里pid /var/run/nginx.pid;events {worker_connections 64; 修改这里# multi_accept on;}

    继续向后找到gzip  去掉前面的注释 修改如下

    gzip on;gzip_disable "msie6";gzip_vary on;gzip_proxied any;gzip_comp_level 6;gzip_buffers 16 8k;gzip_http_version 1.1;gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    Ctrol+O保存 Ctrl+X退出
    在root权限命令行输入命令

    nano /etc/php5/fpm/php.ini

    找到这一段

    ; Maximum amount of memory a script may consume (128MB) ; http://php.net/memory-limit memory_limit = 32M  修改这里 找到这一段 ; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's ; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok ; what PATH_INFO is.  For more information on PATH_INFO, see the cgi specs.  Setting ; this to 1 will cause PHP CGI to fix its paths to conform to the spec.  A setting ; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts ; to use SCRIPT_FILENAME rather than PATH_TRANSLATED. ;http://php.net/cgi.fix-pathinfo cgi.fix_pathinfo=1  修改这里

    在root权限命令行输入命令

    nano /etc/php5/fpm/php-fpm.conf

    找到这一段

    ; The maximum number of processes FPM will fork. This has been design to control ; the global number of processes when using dynamic PM within a lot of pools. ; Use it with caution. ; Note: A value of 0 indicates no limit ; Default Value: 0 process.max = 4  修改这里

    接着改nginx

    nano /etc/nginx/sites-enabled/default

    找到这里 修改如下

    # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.##server {listen   80; ## listen for ipv4; this line is default and implied#listen   [::]:80 default_server ipv6only=on; ## listen for ipv6root /home/pi/www; #建议放在此文件夹内,以后管理更加方便# index index.html index.htm;index index.php index.html index.htm;# Make site accessible from http://localhost/server_name localhost;

    在这句后面增加以下内容

           if (!-e $request_filename) {rewrite ^(.*)$ /index.php$1 last;}

    找到这句
    location ~ .php$ {
    连同后续内容修改如下

       location ~ .*.php(/.*)*${#fastcgi_split_path_info ^(.+.php)(/.+)$;#       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini##       # With php5-cgi alone:#       fastcgi_pass 127.0.0.1:9000;#       # With php5-fpm:fastcgi_pass unix:/var/run/php5-fpm.sock;fastcgi_index index.php;include fastcgi_params;}

    完成之后重新加载服务

    service nginx reloadservice php5-fpm reloadservice mysql reload

    接下来安装phpmyadmin

    mkdir /home/pi/wwwwget http://downloads.sourceforge.net ... -languages.zipunzip phpMyAdmin-3.5.7-all-languages.zip

    最后给文件夹权限

    chown www-data:www-data /home/pi/www -Rchmod 755 /home/pi/www -R

    最后是dnspod的设置

    https://gist.github.com/chuangbo/833369

    这里已有源代码
    需要修改的地方如下

    params = dict(login_email="email", # dnspod的邮箱login_password="password", # 你的密码format="json",domain_id=100, #domain_id http://geekpi.cn/dnspod域名编号去左边的连接获取record_id=100, # record_id 记录id同上,子域名前面的编号sub_domain="www", # 你想要解析的子域名record_line="默认",)

    保存为dnspod.py
    然后输入 nohup python main.py &
    就已经在后台运行了按ctrl+c也不会退出,只有用kill才能删除进程


    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /2 下一条



    手机版|小黑屋|与非网

    GMT+8, 2024-4-26 12:07 , Processed in 0.114274 second(s), 15 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.