计算机‎ > ‎软件‎ > ‎Linux‎ > ‎

刷 WR703N 成 OpenWRT 路由器 续九

发布者:guo rue,发布时间:2015年12月17日 23:32   [ 更新时间:2015年12月17日 23:39 ]
安装 Nginx 软件包 (http)
opkg update
opkg install nginx php5-fastcgi spawn-fcgi

添加用户
useradd www
添加用户组
groupadd www
添加用户到用户组www
usermod -a -G www www

创建 Nginx 的工作目录
mkdir /home/www

将 Nginx 的工作目录绑定到 www 用户
chown -R www:www /home/www

修改Nginx的配置文件
nano /etc/nginx/nginx.conf

#修改设定用户及其用户名
user  www www;
    server {
#设置端口,由于luci 占据了80 ,这里选 8080
        listen       8080; 
        server_name  localhost;
 
        location / {
            root   /home/www; #设置主目录
            index  index.html index.htm;
        }
 
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
 
#下面几行开头的井号去掉
        location ~ .php$ {
            root           /home/www; #cgi目录
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
#别管什么了,这行就这样
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; 
            include        fastcgi_params;
        }
    }

编辑开机启动
nano /etc/rc.local
添加这一句进去
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 2 -f /usr/bin/php-cgi
然后注释掉 exit 0
#exit 0

应用并启动 Nginx 服务
/etc/init.d/nginx enable
/etc/init.d/nginx start


nginx 403 forbidden 原因
1.缺少index.html或者index.php文件
2.把web目录放在用户的所属目录下面,nginx的启动用户默认是nginx的,所以对目录根本没有读的权限,这样就会报403错误了。这个时候,把web目录的权限改大,或者是把nginx的启动用户改成目录的所属用户,重起一下就能解决。

参考
https://wiki.openwrt.org/doc/howto/http.nginx
http://seak.me/archives/130
http://www.cnblogs.com/double-win/p/3885741.html
http://blog.51yip.com/apachenginx/1512.html