termux配置nginx+php

只能以默认用户u0_axx运行,修改用户会报错An error occurred.或者file no found

安装nginx

bash 复制代码
pkg install nginx

安装php-fpm

bash 复制代码
pkg install nginx

修改nginx配置文件,

bash 复制代码
nano ../usr/etc/nginx/nginx.conf

#端口必须设置在1024以上(1024以下需要root,但php-fpm不能以root用户运行,nginx和php-fpm不同用户打开php页面会报错)

bash 复制代码
  server {
        listen       8080;#绑定ipv4的8080端口
        listen       8282;#绑定ipv4的8282端口
        listen       [::]:8181;#绑定ipv6的8181端口
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            #root   /data/data/com.termux/files/usr/share/nginx/html;
            #root   /sdcard/download/jxadcx.github.io;
            root   /data/data/com.termux/files/home/www;#网站根目录
            index  index.html index.htm;
        }

location ~ .php 这一部分去掉注释 , 其中 S C R I P T F I L E N A M E 后面那里填你的网站根目录 这一部分去掉注释,其中SCRIPT_FILENAME后面那里填 你的网站根目录 这一部分去掉注释,其中SCRIPTFILENAME后面那里填你的网站根目录fastcgi_script_name;

bash 复制代码
fastcgi_param  SCRIPT_FILENAME  /data/data/com.termux/files/home/www$fastcgi_script_name;
bash 复制代码
  location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  网站根目录$fastcgi_script_name;
            include        fastcgi_params;
            index index.php;
                }

修改php-fpm配置文件

bash 复制代码
nano ../usr/etc/php-fpm.d/www.conf

注释掉;listen = /data/data/com.termux/files/usr/var/run/php-fpm.sock

bash 复制代码
;listen = /data/data/com.termux/files/usr/var/run/php-fpm.sock

添加一行

bash 复制代码
listen=127.0.0.1:9000

启动nginx和php-fpm

bash 复制代码
nginx
php-fpm

确认以同一用户运行

bash 复制代码
ps -aux | grep nginx | grep -v 'grep'
ps -aux | grep php-fpm | grep -v 'grep'

新建一个php文件在网页访问测试读取txt文件文本

bash 复制代码
touch www/test.php
touch www/test.txt

编辑test.php

bash 复制代码
nano www/test.php
php 复制代码
<!DOCTYPE html>
<html>
<body>

<?php
// 文件路径
$filePath = 'test.txt';

// 检查文件是否存在
if (file_exists($filePath)) {
    // 读取文件内容
    $content = file_get_contents($filePath);
    // 输出文件内容
    echo $content;
} else {
    echo "文件不存在。";
}
?>
</body>
</html>

编辑 test.txt,内容随意

bash 复制代码
nano www/test.txt

网页打开测试

杀死进程

bash 复制代码
 killall php-fpm
 killall nginx
 
相关推荐
damoluomu2 天前
挑 PHP CMS 之前,先学会看它的协议
php
虎头金猫2 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
还是大剑师兰特2 天前
解决nginx错误:http://localhost:7000正常,http://localhost:7000/map 报错404
nginx·大剑师
AI职业加油站2 天前
AI智能体应用工程师证书:政策红利下的职业新风口
大数据·运维·人工智能·学习·职场发展
此冬歌咏2 天前
K8s 节点故障实战:优雅驱逐 31 秒,硬故障 331 秒,以及那个永远 Pending 的 Pod
运维·k8s
xing-xing2 天前
Docker容器中Nginx站点根目录网页配置访问
nginx·docker
-梅2 天前
linux(8) 软硬链接
linux·运维·服务器
张洛闻Eren2 天前
k8s云原生【第十课】:水平 Pod 自动扩缩容
运维·数据库·云原生·kubernetes·github
其实防守也摸鱼2 天前
内网穿透与反向代理:原理、工具与实战指南
android·大数据·运维·安全·网络安全·自动化·渗透
布裘2 天前
【银河麒麟】V4桌面图标消失,右击鼠标没反应排查
运维·银河麒麟·桌面环境