小米路由折騰指南終結(jié)版
小米路由器折騰指南終于要完結(jié)了县昂,折騰到這,我基本上把我的路由器打造的我個人使用沒有什么壓力了棍弄,最后一篇是一個收尾的工作望薄。主要講兩點(diǎn)疟游。
- 自動化安裝Nginx-Mysql-PHP
- Nginx 多域名配置
LNMP自動化腳本
先放鏈接自動化部署 Nginx + Mysql + PHP 環(huán)境
腳本很簡單,不多說痕支,直接引用介紹颁虐。
功能描述
本腳本用于在OpenWRT上自動化部署 Nginx + Mysql + PHP 環(huán)境。腳本運(yùn)行后卧须,Nginx服務(wù)將開啟在8080端口(為了避開OpenWRT本身的界面)另绩。并自動生成一個名稱為index.php的phpinfo文件.數(shù)據(jù)庫將生成一個用戶名為root密碼為admin的用戶。將新建一個www用戶組用戶名為www花嘶,新建/web目錄為Web服務(wù)目錄笋籽,數(shù)據(jù)庫默認(rèn)安裝在/mnt目錄中。相關(guān)配置內(nèi)容路徑不變椭员,可以自行查看车海。
使用方法
將所有文件下載并上傳至OpenWRT的/tmp目錄。使用如下命令:
chmod +x OpenWRT_LNMP_install.sh
./OpenWRT_LNMP_install.sh
環(huán)境測試
完成安裝后打開路由器默認(rèn)地址http://...:8080,安裝若成功則出現(xiàn)phpinfo信息界面
Nginx多域名配置
這個主要是因?yàn)镹gixn會占用一個端口80隘击,如果也想通過域名訪問侍芝,之前路由器界面就要配置一下Nginx的設(shè)置了。
具體方法如下:
下面是具體的配置過程:
- 在 /opt/etc/nginx/ 下創(chuàng)建 vhosts 目錄
mkdir /etc/nginx/vhosts
- 在 /opt/etc/nginx/vhosts/ 里創(chuàng)建一個名字為 example1.com.conf 的文件闸度,把以下內(nèi)容拷進(jìn)去(注意里面的server_name配置換成你自己的名稱)
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;
}
}
- 打開 /opt/etc/nginix.conf 文件竭贩,在相應(yīng)位置加入 include 把以上2個文件包含進(jìn)來
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;
}
}
# 包含所有的虛擬主機(jī)的配置文件
include /usr/local/etc/nginx/vhosts/*;
}
5蚜印、重啟 Nginx
/opt/etc/init.d/nginx restart
這樣設(shè)置完就可以即訪問自己的網(wǎng)站也不會影響路由器界面了莺禁。
尾巴
小米路由的折騰寫了很久了,時間跨度怕是有一年了窄赋,這一年折騰了很多個不眠之夜哟冬,雖然自己很累但是真的很開心。:)