特异个体 发表于 2023-2-26 14:28:52

AXT1800 编译安装nginx并支持php8搭建web服务器

按照https://forum.gl-inet.cn/forum.php?mod=viewthread&tid=244&extra=page%3D1教程,实际上原版的feeds中就包含了很多额外的插件,但没有放开。

在make编译前,可以执行
./script/feeds update -a
./script/feeds install -a
这样就安装很多外插件,包括php8。
编译选项中新增支持php8,可以选中后把需要的依赖都加上,路径在Languages下,比如cgi、 mysqli等。截图见附件。
本人选项参考:
CONFIG_PACKAGE_php8-mod-ctype=y
CONFIG_PACKAGE_php8-mod-mysqli=y
CONFIG_PACKAGE_php8-mod-mysqlnd=y
CONFIG_PACKAGE_php8-mod-openssl=y
CONFIG_PACKAGE_php8-mod-pdo=y
CONFIG_PACKAGE_php8-mod-pdo-mysql=y
CONFIG_PACKAGE_php8-mod-pdo-sqlite=y
CONFIG_PACKAGE_php8-mod-session=y
CONFIG_PACKAGE_php8-mod-sockets=y
CONFIG_PACKAGE_php8-mod-sqlite3=y
CONFIG_PACKAGE_php8-mod-zip=y

nginx是原生支持的,选项参考:
CONFIG_PACKAGE_luci-nginx=y
CONFIG_PACKAGE_nginx-all-module=y
CONFIG_PACKAGE_nginx-mod-luci=y


编译后,启动AXT1800,在etc/nginx下有nginx.conf文件,
原本的文件没有虚拟服务器配置,可以按照如下步骤配置(仅供参考):
1、/etc/nginx/nginx.conf
user root;
worker_processesauto;
pid      /var/run/nginx.pid;
error_log/var/log/nginx_error.log;
events {
    use epoll;
    worker_connections1024;
}
http {
server_names_hash_bucket_size 64;
include /etc/nginx/mime.types;
sendfile on;
client_max_body_size 128M;
large_client_header_buffers 2 1k;
gzip on;
gzip_vary on;
gzip_proxied any;
keepalive_timeout 60;
include vhost.conf;
}


2、新建/etc/nginx/vhost.conf (分离server的配置,指定端口号和web根目录)
server {
    listen 8080;   #nginx另起进程,端口号自行设置,但不可与uhttpd的80端口相同。
    listen [::]:8080;
    server_namelocalhost;
    root /usr/www;#自行设置
    indexindex.html index.htm index.php default.php;

    # redirect server error pages to the static page /50x.html
    error_page   500 502 503 504/50x.html;
    location = /50x.html {
      root   html;
    }

    location ~\.php$ {#支持php
      fastcgi_pass unix:/var/run/php8-fpm.sock;
      fastcgi_index index.php;
      fastcgi_split_path_info ^(.+\.php)(.*)$;

      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_param PATH_INFO $fastcgi_path_info;
      include /etc/nginx/fastcgi_params;
    }

    location = / {#支持访问lan口ip跳转到uhttpd的luci界面
      return 302 http://$host/cgi-bin/luci/;
    }

    location /cgi-bin/luci/ {
      client_max_body_size 128m;
      proxy_pass http://127.0.0.1/cgi-bin/luci/;
    }

    location /luci-static/ {
      alias /www/luci-static/;
    }
}


3、/etc/php.ini
此文件只需要改动一个地方:
doc_root = "/usr/www"   
这里按照自定义设置路径即可。

4、在任意目录新建sh脚本nginx.sh。如下:
#!/bin/sh

NGINX_CONFIG="/etc/nginx/nginx.conf"
PHP_FPM_CONFIG="/etc/php8-fpm.conf"
PHP_CONFIG="/etc/php.ini"


start() {
mkdir -p /var/log/nginx /var/lib/nginx
/usr/bin/php8-fpm -R -c $PHP_CONFIG -y $PHP_FPM_CONFIG
/usr/sbin/nginx -c $NGINX_CONFIG >/dev/null 2>&1 &
/etc/init.d/uhttpd start
}


stop() {
/usr/sbin/nginx -c $NGINX_CONFIG -s stop >/dev/null 2>&1 &
killall -9 php8-fpm >/dev/null 2>&1 &
rm -f /var/run/php8-fpm.pid
rm -f /var/log/php8-fpm.log
rm -f /var/run/php8-fpm.sock
/etc/init.d/uhttpd stop
}

if [ $1 -eq 1 ]; then
        start
elif [ $1 -eq 0 ]; then
        stop
fi

如上配置完成后,给nginx.sh添加执行权限:
chmod +x nginx.sh
然后
./nginx.sh 0
./nginx.sh 1
即可重启nginx服务
效果:
浏览器访问lanip:8080访问到自定义的web服务器,
直接访问lanip则访问luci管理页面。



oliverlee 发表于 2023-2-27 10:13:34

能把编译好的包分享一下吗:handshake
页: [1]
查看完整版本: AXT1800 编译安装nginx并支持php8搭建web服务器