├── README.md ├── LICENSE ├── .gitignore └── install.sh /README.md: -------------------------------------------------------------------------------- 1 | # termux webserver with ngrok 2 | 3 | #### how to make things right 4 | 5 | - install termux android app from google appstore 6 | - start termux app on your android and wait for the installation to finish 7 | - update , install curl with: 8 | 9 | ```apt update && apt install -y curl``` 10 | 11 | - download the script and execute it with the command below and wait for a while: 12 | 13 | ```sh -c "$(curl -fsSL https://raw.githubusercontent.com/brunobell/termux_webserver_with_ngrok/master/install.sh)"``` 14 | 15 | - when you are done with the contemporary mobile server, remember to shut apache/nginx server down with pkill -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 broono 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | 49 | # Translations 50 | *.mo 51 | *.pot 52 | 53 | # Django stuff: 54 | *.log 55 | local_settings.py 56 | 57 | # Flask stuff: 58 | instance/ 59 | .webassets-cache 60 | 61 | # Scrapy stuff: 62 | .scrapy 63 | 64 | # Sphinx documentation 65 | docs/_build/ 66 | 67 | # PyBuilder 68 | target/ 69 | 70 | # Jupyter Notebook 71 | .ipynb_checkpoints 72 | 73 | # pyenv 74 | .python-version 75 | 76 | # celery beat schedule file 77 | celerybeat-schedule 78 | 79 | # SageMath parsed files 80 | *.sage.py 81 | 82 | # dotenv 83 | .env 84 | 85 | # virtualenv 86 | .venv 87 | venv/ 88 | ENV/ 89 | 90 | # Spyder project settings 91 | .spyderproject 92 | .spyproject 93 | 94 | # Rope project settings 95 | .ropeproject 96 | 97 | # mkdocs documentation 98 | /site 99 | 100 | # mypy 101 | .mypy_cache/ 102 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/data/data/com.termux/files/usr/bin/bash 2 | 3 | # device arch 4 | DEVICE_ARCH=$(uname -m) 5 | # echo $DEVICE_ARCH 6 | 7 | # which country 8 | COUNTRY=$(curl -s "http://api.ipaddress.com/iptocountry?format=txt") 9 | 10 | if [ "$COUNTRY" = "CN" ] 11 | then 12 | echo "You are in China, switching to tuna mirrors..." 13 | SOURCES_OLD=/data/data/com.termux/files/usr/etc/apt/sources.list 14 | SOURCES_NEW=/data/data/com.termux/files/usr/etc/apt/sources.list.bak 15 | if [ -f "$SOURCES_OLD" ]; then # backup 16 | cp $SOURCES_OLD $SOURCES_NEW 17 | echo $SOURCES_OLD" ---> "$SOURCES_NEW" ok!" 18 | fi 19 | # update to tsinghua :) 20 | echo "deb [arch=all,"$DEVICE_ARCH"] http://mirrors.tuna.tsinghua.edu.cn/termux stable main" > $SOURCES_OLD 21 | apt update && echo "update cache success" 22 | fi 23 | 24 | if [ ! -f /data/data/com.termux/files/home/ngrok ] 25 | then 26 | case $DEVICE_ARCH in 27 | arm | aarch64) 28 | NGROK_URL=https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-arm.zip 29 | ;; 30 | i686) 31 | NGROK_URL=https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-386.zip 32 | ;; 33 | x86_64) 34 | NGROK_URL=https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip 35 | ;; 36 | *) 37 | echo "Unknown arch detected" 38 | exit 1 39 | ;; 40 | esac 41 | echo "ngrok download url: "$NGROK_URL 42 | curl -o /data/data/com.termux/files/home/ngrok.zip $NGROK_URL 43 | unzip /data/data/com.termux/files/home/ngrok.zip 44 | fi 45 | 46 | echo "a. apache, b. nginx, c. python simple HTTP server" 47 | 48 | while true 49 | do 50 | read -p "which backend of webserver would you prefer? " OPTION 51 | case $OPTION in 52 | a | b | c | A | B | C ) 53 | break 54 | ;; 55 | *) 56 | continue 57 | ;; 58 | esac 59 | done 60 | 61 | case $OPTION in 62 | a | A) 63 | apt install -y apache2 && nohup httpd 1>/dev/null 2>&1 & 64 | ;; 65 | b | B) 66 | apt install -y nginx && nohup nginx 1>/dev/null 2>&1 & 67 | ;; 68 | c | C) 69 | apt install -y python && nohup python -m http.server 8080 1>/dev/null 2>&1 & 70 | ;; 71 | *) 72 | break 73 | ;; 74 | esac 75 | 76 | chmod 755 /data/data/com.termux/files/home/ngrok 77 | ./ngrok http 8080 --------------------------------------------------------------------------------