快速安装配置的方式:
1、安装
yum install nginx
2、启用:
sudo systemctl start nginx
关于systemctl这一个系列的指令,包括开启、关闭、状态查看、重启等可以看下阮老师的文章http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-commands.html
3、配置你的站点,先打开配置文件
vim /etc/nginx/nginx.conf
将root改为你静态资源存放的地址,这个静态资源就可以通过机器的ip或配置的域名访问了。nginx的能力很多,更复杂的配置建议去官网查。
自定义目录安装:
1、安装c++环境
yum install gcc-c++
2、安装正则库
yum install -y pcre pcre-devel
3、安装加解压库
yum install -y zlib zlib-devel
4、安装安全套接字
yum install -y openssl openssl-devel
5、打开nginx官网,选择当前的稳定版本安装,或者你需要的版本
https://nginx.org/en/download.html
选择当前稳定版,复制地址执行下载,
wegt -c https://nginx.org/download/nginx-1.20.2.tar.gz
6、对下载文件解压
tar -zxvf nginx-1.20.2.tar.gz
cd nginx-1.20.2/
7、编译
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_sub_module --with-http_gzip_static_module --with-pcre
8、安装
make && make install