一、安装依赖
sudo yum install -y gcc pcre-devel zlib-devel openssl-devel wget make
二、下载源码
wget http://nginx.org/download/nginx-1.22.1.tar.gz
三、解压源码
tar -zxvf nginx-1.22.1.tar.gz
四、进入源码目录
d nginx-1.22.1
五、配置Nginx
使用 ./configure 配置 Nginx。你可以根据需要添加模块或选项,以下是一个基本配置:
./configure --prefix=/usr/local/nginx --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_ssl_module --with-http_v2_module
如果不清楚怎么配置,可以查询另外一台服务器,再进行配置:
注意:-V 大写
[root@localhost conf]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.22.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_ssl_module --with-http_v2_module
六、编译和安装
make
sudo make install
七、启动安装
sudo /usr/local/nginx/sbin/nginx
八、验证安装
http://192.168.20.94/
九、设置开机自启动
sudo vi /etc/systemd/system/nginx.service
添加如下内容:
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
十、启用并启动服务
注意:如果之前手动启动过,先杀掉之前的进程,再执行下面命令
sudo systemctl enable nginx
sudo systemctl start nginx
十一、检查nginx状态
sudo systemctl status nginx