安装nginx
下载地址: https://nginx.org/en/download.html
这里选择nginx稳定linux版
把文件上传至linux系统中,不会上传的朋友,可以参考这篇文章 https://blog.csdn.net/weixin_45433031/article/details/120497126
解压文件:
tar -zxvf nginx-1.22.0
依次执行下面代码进行配置:
./configure
make
make install
配置成功后输入下方命令检测
whereis nginx
若出现目录,则安装成功。
安装nginx过程中可能会出现的bug以及解决办法:
缺少PCRE库
如果没有安装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=<path> option.
安装PCRE库
我们可以去下载一下PCRE库,下载地址:https://sourceforge.net/projects/pcre/
找到最新版的tar.gz文件下载就可以了
下载后上传至linux系统中,使用下面命令解压
tar -zxvf pcre-8.45.tar.gz
解压后给予pcre-8.45目录读写权限
chmod -R 777 pcre-8.45
给予权限后进入pcre-8.45目录运行
./configure
若报错
error: Invalid C++ compiler or C++ compiler flags
说明没有安装c++编译器,首先分别查看一下gcc 和g++ 是否安装
gcc --version
g++ --version
安装gcc和g++
安装gcc
sudo apt install gcc
安装g++
sudo apt install g++
gcc和g++安装好之后回到pcre-8.45目录再次执行
./configure
成功后依次执行
make
make install
pcre库到这就算安装成功了,现在回到nginx目录下执行
./configure
缺少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=<path> option.
安装zlib库
安装zlib库,下载地址:http://www.zlib.net/fossils/
我安装的是最新版2022年的,在最下面
解压安装步骤:
进入zlib根目录后
./configure
make
make install
运行nginx
使用下方命令找到nginx安装路径
whereis nginx
查看nginx目录 -> config目录下的nginx.conf 查看端口号
默认配置下都是80
返回nginx根目录
进入sbin目录,里面只有一个可执行文件nginx,运行
./nginx
运行后,输入ifconfig查看服务器ip
然后在本机网址上搜索IP+端口号就可以进入nginx页面了