### 设置安装源
[centos@localhost root]$ sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
获取http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
警告:/var/tmp/rpm-tmp.fyErPh: 头V4 RSA/SHA1 Signature, 密钥 ID 7bd9bf62: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:nginx-release-centos-7-0.el7.ngx ################################# [100%]
[centos@localhost root]$ sudo yum install nginx
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.huaweicloud.com
nginx | 2.9 kB 00:00
nginx/x86_64/primary_db | 67 kB 00:01
正在解决依赖关系
--> 正在检查事务
---> 软件包 nginx.x86_64.1.1.20.1-1.el7.ngx 将被 安装
--> 解决依赖关系完成
依赖关系解决
================================================================================
Package 架构 版本 源 大小
================================================================================
正在安装:
nginx x86_64 1:1.20.1-1.el7.ngx nginx 790 k
事务概要
================================================================================
安装 1 软件包
总下载量:790 k
安装大小:2.8 M
Is this ok [y/d/N]: y
Downloading packages:
nginx-1.20.1-1.el7.ngx.x86_64.rpm | 790 kB 00:13
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 数据库已被非 yum 程序修改。
正在安装 : 1:nginx-1.20.1-1.el7.ngx.x86_64 1/1
----------------------------------------------------------------------
Thanks for using nginx!
Please find the official documentation for nginx here:
* https://nginx.org/en/docs/
Please subscribe to nginx-announce mailing list to get
the most important news about nginx:
* https://nginx.org/en/support.html
Commercial subscriptions for nginx are available on:
* https://nginx.com/products/
----------------------------------------------------------------------
验证中 : 1:nginx-1.20.1-1.el7.ngx.x86_64 1/1
已安装:
nginx.x86_64 1:1.20.1-1.el7.ngx
完毕!
## 查看版本
[centos@localhost root]$ nginx -version
nginx version: nginx/1.20.1
[centos@localhost root]$ whereis nginx
nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz
```
## 设置开机自动启动
[centos@localhost root]$ sudo systemctl start nginx
[centos@localhost root]$ sudo systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
## nginx 80端口改成6180
[centos@localhost root]$ cd /etc/nginx/conf.d
[centos@localhost conf.d]$ ls
default.conf
[centos@localhost conf.d]$ sudo vi default.conf
### 访问测试
192.168.1.147:8080
https://118.213.240.3:6180/
## 反向代理mysql
和http同级
stream {
server {
listen 6181;
proxy_connect_timeout 1s;
proxy_timeout 300s;
proxy_pass 127.0.0.1:3306;
}
}