nginx的yum安装
http://www.nginx.org/ 官方的网站
Nginx版本类型
Mainline version: 主线版,即开发版
Stable version: 最新稳定版,生产环境上建议使用的版本
Legacy versions: 旧版本
yum安装nginx的官网
切忌: 安装之前一定要检查yum源是否有问题,网络是否正常,防火墙和selinux是否关闭
忘记怎么操作的亲可以去看看初始化,很详细哦
- 配置yum源
安装所需要的工具
yum install yum-utils -y
若是普通账户,可以提权使用
[root@localhost ~]# yum install yum-utils -y
2配置源
[root@localhost ~]# vim /etc/yum.repos.d/nginx.repo ##进入配置文件
[nginx-stable] 随便写一个名称
name=nginx stable repo 随便写
baseurl=http://nginx.org/packages/centos/ r e l e a s e v e r / releasever/ releasever/basearch/ ##安装的地址
gpgcheck=0 ##关闭签名机制,一定要关
enabled=1 ##开机启动,1为打开,0为关闭
退出,保存
3 安装
一切准备完毕之后,便可以安装了
[root@localhost ~]# yum install nginx -y
安装万之后,可以用nginx -v 查看是不是自己想要的版本,此处是安装的1.18.0
[root@localhost ~]# nginx -v
nginx version: nginx/1.18.0
要想查看详细信息,可以写nginx -V
nginx -V
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
4 启动nginx
systemctl start nginx 启动nginx
ss -auntpl | grep nginx 查看端口是否启动,端口为80
systemctl enable nginx 设置开机自启动
编译安装
1 安装编译环境
yum -y install gcc gcc-c++
2、安装pcre软件包(使nginx支持http rewrite模块)
yum install -y pcre pcre-devel gd-devel
3、安装openssl-devel(使nginx支持ssl)
yum install -y openssl openssl-devel
4、安装zlib
yum install -y zlib zlib-devel
5、创建用户nginx
useradd nginx ##创建用户
passwd nginx ##设置密码
6、安装nginx
wget http://nginx.org/download/nginx-1.16.0.tar.gz ##压缩包
tar xzf nginx-1.16.0.tar.gz -C /usr/local/src ## 解压
cd /usr/local/src/nginx-1.16.0/ ##切换路径
[root@localhost ngin-1.16.0]# ./configure --prefix=/usr/local/nginx --group=nginx --user=nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/tmp/nginx/client_body --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module --with-stream
7 ##装各种配置的路径
[root@localhost nginx-1.16.0]# make && make install ## make 编译之后安装
[root@localhost ~]#/usr/local/nginx/sbin/nginx -V #查看安装的模块
8 可以根据自己的需求更改配置文件
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t 检查配置文件是否正确
[root@localhost ~]# mkdir -p /tmp/nginx #创建一个目录
启动nginx
/usr/local/nginx/sbin/nginx
完成了nginx的编译安装
补充
nginx -c /path/nginx.conf # 以特定目录下的配置文件启动nginx:
nginx -s reload # 修改配置后重新加载生效
nginx -s stop # 快速停止nginx
nginx -s quit # 完整有序的停止nginx
nginx -t # 测试当前配置文件是否正确
nginx -t -c /path/to/nginx.conf # 测试特定的nginx配置文件是否正确
今天就到这里啦,有不懂的宝宝可以评论哦!!1