一、安装nginx
1.
到【nginx: download】下载,上传压缩包到非【/usr/local/】目录
解压:
tar -zxvf nginx-1.20.2.tar.gz -C /
2.
cd nginx-1.20.2
3.
./configure --prefix=/usr/local/nginx-1.20.2 --with-http_ssl_module --with-http_stub_status_module
#配置configure --prefix 代表安装的路径,--with-http_ssl_module 安装ssl,--with-http_stub_status_module查看nginx的客户端状态。
如果执行后报错
./configure: error: the HTTP rewrite module requires the PCRE library.
则执行语句,安装
yum -y install pcre-devel
如果执行后报错
./configure: error: SSL modules require the OpenSSL library.
则执行语句,安装
yum -y install openssl openssl-devel
4.
make & make install
5.
cd /usr/local/nginx-1.20.2/sbin/
二、添加开机自启
1.
vim /etc/rc.local
2.
在文档底部添加
/usr/local/nginx-1.20.2/sbin/nginx
3.
执行语句
chmod +x /etc/rc.d/rc.local
使/etc/rc.d/rc.local变成可执行文件。
ps:一些命令
cd到sbin目录下
启动———./nginx
检验规则———./nginx -t
重启———./nginx -s reload
验证nginx是否启动
ps -ef | grep nginx