Termux安装Nginx


安装命令

pkg install nginx

查看Nginx版本号

nginx -v
nginx version: nginx/1.27.1

运行Nginx

nginx

访问网站,注意:默认监听端口为8080

我的手机Nginx访问地址为:http://192.168.1.101:8080/

重启Nginx

nginx -s reload

停止运行Nginx

nginx -s quit

查看Nginx文件位置

pkg files nginx
/.
/data
/data/data
/data/data/com.termux
/data/data/com.termux/files
/data/data/com.termux/files/usr
/data/data/com.termux/files/usr/bin
/data/data/com.termux/files/usr/bin/nginx
/data/data/com.termux/files/usr/etc
/data/data/com.termux/files/usr/etc/nginx
/data/data/com.termux/files/usr/etc/nginx/fastcgi.conf
/data/data/com.termux/files/usr/etc/nginx/fastcgi_params
/data/data/com.termux/files/usr/etc/nginx/koi-utf
/data/data/com.termux/files/usr/etc/nginx/koi-win
/data/data/com.termux/files/usr/etc/nginx/mime.types
/data/data/com.termux/files/usr/etc/nginx/nginx.conf
/data/data/com.termux/files/usr/etc/nginx/scgi_params
/data/data/com.termux/files/usr/etc/nginx/uwsgi_params
/data/data/com.termux/files/usr/etc/nginx/win-utf
/data/data/com.termux/files/usr/share
/data/data/com.termux/files/usr/share/doc
/data/data/com.termux/files/usr/share/doc/nginx
/data/data/com.termux/files/usr/share/doc/nginx/copyright
/data/data/com.termux/files/usr/share/man
/data/data/com.termux/files/usr/share/man/man8
/data/data/com.termux/files/usr/share/man/man8/nginx.8.gz
/data/data/com.termux/files/usr/share/nginx
/data/data/com.termux/files/usr/share/nginx/html
/data/data/com.termux/files/usr/share/nginx/html/50x.html
/data/data/com.termux/files/usr/share/nginx/html/index.html
/data/data/com.termux/files/usr/share/vim
/data/data/com.termux/files/usr/share/vim/vimfiles
/data/data/com.termux/files/usr/share/vim/vimfiles/ftdetect
/data/data/com.termux/files/usr/share/vim/vimfiles/ftdetect/nginx.vim
/data/data/com.termux/files/usr/share/vim/vimfiles/indent
/data/data/com.termux/files/usr/share/vim/vimfiles/indent/nginx.vim
/data/data/com.termux/files/usr/share/vim/vimfiles/syntax
/data/data/com.termux/files/usr/share/vim/vimfiles/syntax/nginx.vim
/data/data/com.termux/files/usr/var
/data/data/com.termux/files/usr/var/lib
/data/data/com.termux/files/usr/var/lib/nginx
/data/data/com.termux/files/usr/var/lib/nginx/client-body
/data/data/com.termux/files/usr/var/lib/nginx/fastcgi
/data/data/com.termux/files/usr/var/lib/nginx/proxy
/data/data/com.termux/files/usr/var/lib/nginx/scgi
/data/data/com.termux/files/usr/var/lib/nginx/uwsgi
/data/data/com.termux/files/usr/var/log
/data/data/com.termux/files/usr/var/log/nginx
/data/data/com.termux/files/usr/var/service
/data/data/com.termux/files/usr/var/service/nginx
/data/data/com.termux/files/usr/var/service/nginx/down
/data/data/com.termux/files/usr/var/service/nginx/log
/data/data/com.termux/files/usr/var/service/nginx/log/run
/data/data/com.termux/files/usr/var/service/nginx/run

配置文件:/data/data/com.termux/files/usr/etc/nginx/nginx.conf

网站代码文件目录:/data/data/com.termux/files/usr/share/nginx/html

查看配置文件

cat /data/data/com.termux/files/usr/etc/nginx/nginx.conf
#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


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"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       8080;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /data/data/com.termux/files/usr/share/nginx/html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /data/data/com.termux/files/usr/share/nginx/html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

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

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

根据自己的需要修改配置文件。