一、安装编译工具及库文件
准备第三方支持库源码
- nginx-1.21.6.tar.gz
- openssl-master.zip
- pcre2-10.39.tar.gz
- zlib-1.2.11.tar.gz
解压
- tar xzvf nginx-1.21.6.tar.gz
- unzip openssl-master.zip
- tar zxvf pcre2-10.39.tar.gz
- tar zxvf zlib-1.2.11.tar.gz
-
或使用命令安装
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
-
安装每个库 --指定路径安装
./configure --prefix=/usr/local/nginx/pcre2-10.39 make && sudo make install ./Configure --prefix=/usr/local/nginx/openssl-master make && sudo make install ./configure --prefix=/usr/local/nginx/zlib-1.2.11 make && sudo make install
-
安装Nginx
下载源码或者命令行安装
下载源码解压后进入安装目录执行如下命令 后边指令库是源码目录,不是安装目录
./configure --prefix=/usr/local/nginx/nginx --prefix=/usr/local/nginx --with-http_addition_module --with-http_gzip_static_module --with-http_secure_link_module --with-http_stub_status_module --with-stream --with-pcre=/home/sxt/share/pcre2-10.39 --with-zlib=/home/sxt/share/zlib-1.2.11 --with-openssl=home/sxt/share/openssl-master ... make ... sudo make install
-
查看版本
安装完进入到安装指定的路径下
sxt@ubuntu:~/share/nginx-1.21.6$ cd /usr/local/nginx/ sxt@ubuntu:/usr/local/nginx$ ./sbin/nginx -v nginx version: nginx/1.21.6
-
启动和停止
-
检查配置文件的正确性
sxt@ubuntu:/usr/local/nginx$ sudo ./sbin/nginx -t -c ./conf/nginx.conf nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
-
使用默认的配置文件启动停止
sudo ./sbin/nginx #启动 sudo ./sbin/nginx -s reload # 重新载入配置文件 sudo ./sbin/nginx -s reopen # 停止 Nginx sudo ./sbin/nginx -s stop # 快速停止 Nginx sudo ./sbin/nginx -s quit # 快速停止 Nginx ps -aux | grep nginx #查看进程
-
使用指定的配置文件启动
sudo ./sbin/nginx -c ./conf/nginx.conf #启动
-
- 查看IP并使用浏览器访问
参考资料: