- 安装gcc环境
yum -y install gcc gcc-c++ pcre-devel zlib-devel openssl-devel libxml2-devel libxslt-devel gd-devel GeoIP-devel jemalloc-devel libatomic_ops-devel perl-devel perl-ExtUtils-Embed
Ubuntu系统命令
sudo apt-get update
apt-get install gcc libpcre3 libpcre3-dev zlib1g zlib1g-dev openssl libssl-dev libxml2 libxml2-dev libxslt-dev
- 查看是否已经有gcc环境
gcc -v
- 解压nginx压缩包
tar -zxvf nginx-1.20.2.tar.gz
- 进入nginx压缩包
cd nginx-1.20.2/
- 编译nginx并且安装https模块
./configure --with-threads --with-file-aio --with-pcre-jit --with-compat --with-http_v2_module --with-http_ssl_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_realip_module --with-http_geoip_module=dynamic --with-stream_geoip_module=dynamic --with-stream_ssl_preread_module --with-stream_realip_module --with-stream=dynamic --with-stream_ssl_module
- 安装
make && make install
如果安装报错:make: *** No rule to make target `build', needed by `default'. Stop.
yum -y install make zlib-devel libtool openssl openssl-devel
安装完成后,进入:/usr/local/nginx/sbin,执行下面的命令,启动nginx
./nginx
关闭nginx命令
./nginx -s stop
重启nginx命令
./nginx -s restart
如果想配置全局变量可以执行下面命令
# 编辑配置文件
vim /etc/profile
在配置文件中最下面添加如下内容
PATH=$PATH:/usr/local/nginx/sbin
重新加载配置文件
source /etc/profile