(Termux)安装Nginx(其他的也适用)

这里没有直接的nginx包了,需要下载进行编辑安装了

一.下载

创建文件夹

mkdir /usr/local/nginx
cd /usr/local/nginx

下载

wget https://nginx.org/download/nginx-1.20.2.tar.gz

解压

tar -zxvf nginx-1.20.2.tar.gz 

进入解压文件夹

cd nginx-1.20.2

二.配置

指定nging编译配置安装路径--prefix是指定nginx安装路径等号左右不要有空格

./configure --prefix=/usr/local/nginx

使用./configure --prefix=路径之后可能出现bash: configure: command not found这个错误

可能是由于没有安装gccc++编译器出现的问题导致无法使用报错

yum install gcc gcc-c++ -y

然后在运行一遍上面的./configure进行测试是否安装成功
然后这一层你发现可以编译,但是最后打印出下面这个东东,这个是由于没有安装pcre库导致的

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre= option.

yum install  pcre pcre-devel  -y

或者会出现下面这个东东,这个是由于没有安装zlib库导致的

./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib= option.

yum install  zlib zlib-devel   -y

也可能会出现下面这个东东,里面说的是没有使用OpenSSL,我们直接指定路径让他找到

Configuration summary

  • using system PCRE library
  • OpenSSL library is not used
  • using system zlib library

nginx path prefix: “/usr/local/nginx”
nginx binary file: “/usr/local/nginx/sbin/nginx”
nginx modules path: “/usr/local/nginx/modules”
nginx configuration prefix: “/usr/local/nginx/conf”
nginx configuration file: “/usr/local/nginx/conf/nginx.conf”
nginx pid file: “/usr/local/nginx/logs/nginx.pid”
nginx error log file: “/usr/local/nginx/logs/error.log”
nginx http access log file: “/usr/local/nginx/logs/access.log”
nginx http client request body temporary files: “client_body_temp”
nginx http proxy temporary files: “proxy_temp”
nginx http fastcgi temporary files: “fastcgi_temp”
nginx http uwsgi temporary files: “uwsgi_temp”
nginx http scgi temporary files: “scgi_temp”

yum install openssl openssl-devel -y

这里运行的就有点不一样了

./configure --prefix=/usr/local/nginx --with-http_ssl_module

这里只是记录可能发生的错误,安装的时候直接都下载下来就行,这样一步一步确实麻烦
首先要安装automake

yum install automake -y

然后进行编译

make

在进行安装

make install

三.测试

进入sbin目录

cd  /usr/local/nginx/sbin

启动nginx

./nginx

出现错误nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
对于Termux来说,手机不能使用80端口(好像是这样的忘了怎么说的了)
那就修改一下端口

cd /usr/local/nginx/conf
vi nginx.conf

将下面的端口号进行修改,这里我改成8080
在这里插入图片描述
然后重新启动nginx,发现运行成功,使用ps -ef|grep nginx可以查看端口号

在这里插入图片描述

然后访问网址ip+端口号,直接访问成功
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_45853881/article/details/127497228
今日推荐