nginx -v 检查是否安装
方法一:
apt install nginx
注:此方法nginx安装完成后文件位置
/usr/sbin/nginx #主程序
/etc/nginx #存放配置文件
/usr/share/nginx #存放静态文件
/var/log/nginx #存放日志
方法二:
1.cd /usr/local 进入目录
2.mkdir nginx 创建文件
3.cd /usr/local/nginx
4.wget http://nginx.org/download/nginx-1.22.1.tar.gz 下载包
5.tar -xvf nginx-1.22.1.tar.gz 解压
6.cd nginx-1.22.1
7../configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module 设置参数,支持ssl
错误1:./configure: error: C compiler cc is not found
解决方法:apt install g++
错误2:./configure: error: the HTTP rewrite module requires the PCRE library.
解决方法:apt install libpcre3 libpcre3-dev
再次执行第7步
错误3:./configure: error: SSL modules require the OpenSSL library.
解决方法: apt install openssl libssl-dev
错误4:./configure: error: the HTTP gzip module requires the zlib library.
解决方法: apt install zlib1g zlib1g-dev
再次执行第7步,没有错误后,进行下一步
8.make
9.make install
10.cd /usr/local/nginx/sbin
./nginx -t 查看是否安装成功
11../nginx
注:非root用户需要在命令前加上sudo