Geek人生程序员程序员的日常

小米路由折腾指南(完结篇)

2016-06-27  本文已影响1331人  陆行鸟

小米路由折腾指南终结版

小米路由器折腾指南终于要完结了,折腾到这,我基本上把我的路由器打造的我个人使用没有什么压力了,最后一篇是一个收尾的工作。主要讲两点。

  1. 自动化安装Nginx-Mysql-PHP
  2. Nginx 多域名配置

LNMP自动化脚本

先放链接自动化部署 Nginx + Mysql + PHP 环境

脚本很简单,不多说,直接引用介绍。

功能描述
本脚本用于在OpenWRT上自动化部署 Nginx + Mysql + PHP 环境。脚本运行后,Nginx服务将开启在8080端口(为了避开OpenWRT本身的界面)。并自动生成一个名称为index.php的phpinfo文件.数据库将生成一个用户名为root密码为admin的用户。将新建一个www用户组用户名为www,新建/web目录为Web服务目录,数据库默认安装在/mnt目录中。相关配置内容路径不变,可以自行查看。
使用方法
将所有文件下载并上传至OpenWRT的/tmp目录。使用如下命令:
chmod +x OpenWRT_LNMP_install.sh
./OpenWRT_LNMP_install.sh
环境测试
完成安装后打开路由器默认地址http://...:8080,安装若成功则出现phpinfo信息界面

Nginx多域名配置

这个主要是因为Ngixn会占用一个端口80,如果也想通过域名访问,之前路由器界面就要配置一下Nginx的设置了。

具体方法如下:

下面是具体的配置过程:

mkdir /etc/nginx/vhosts

server {
        listen  80;
        server_name  example1.com www. example1.com;

        access_log  /www/access_ example1.log  main;

        location / {
            root   /www/example1.com;
            index  index.php index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }

       # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /www/example1.com/$fastcgi_script_name;
            include        fastcgi_params;
        }

        location ~ /\.ht {
            deny  all;
        }
}
user  nginx;
worker_processes  1;

# main server error log
error_log   /var/log/nginx/error.log ;
pid /var/run/nginx.pid;

events {
    worker_connections  1024;
}

# main server config
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"';

    sendfile        on;
    #tcp_nopush     on;
        #keepalive_timeout  0;
    keepalive_timeout  65;
    gzip  on;

    server {
            listen         80;
            server_name     _;
            access_log      /var/log/nginx/access.log main;
            server_name_in_redirect  off;
            location / {
                    root  /usr/share/nginx/html;
                    index index.html;
            }
    }

    # 包含所有的虚拟主机的配置文件
    include /usr/local/etc/nginx/vhosts/*;
}

5、重启 Nginx

/opt/etc/init.d/nginx restart

这样设置完就可以即访问自己的网站也不会影响路由器界面了。

尾巴

小米路由的折腾写了很久了,时间跨度怕是有一年了,这一年折腾了很多个不眠之夜,虽然自己很累但是真的很开心。:)

上一篇 下一篇

猜你喜欢

热点阅读