Centos7.6安装nginx

实现步骤:

1.先下载Linux版本nginx

2.执行以下命令

bash 复制代码
##yum -y install openssl openssl-devel ## 可以不用执行
yum -y install gd-devel ##下载环境
yum install pcre pcre-devel
tar -zxvf nginx-1.21.6.tar.gz ##解压
mv nginx-1.21.4 nginx ##重命名
cd nginx#打开文件
./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/nginx.conf ##加载配置
make&&make install ##下载编译
systemctl start firewalld ##开启防火墙
firewall-cmd --zone=public --add-port=443/tcp --permanent ##开启端口
firewall-cmd --zone=public --add-port=80/tcp --permanent  ##开启端口
firewall-cmd --zone=public --add-service=http --permanent  ##开启http服务
firewall-cmd --reload ##重启防火墙
/usr/local/nginx/sbin/nginx ##启动nginx
firewall-cmd --list-ports ##查看端口
firewall-cmd --list-all ##查看所有规则,重点关注service服务 和ports端口

3.Nginx相关配置

bash 复制代码
server {
    listen 80;
    server_name example.com;

    location / { #对应前端
        root /var/www/html;#默认跳转到/var/www/html文件夹下面的 index.html
        index index.html;
        try_files $uri $uri/ =404;

        limit_conn addr 10;  # 每个 IP 最多允许 10 个连接
        limit_req zone=one burst=5;  # 每秒允许 1 个请求,突发请求最多 5 个
    }
 location /sysManage5 { #每一个local 表示一个服务拦截
            alias /home/sf5_web/sysManage5;  
				try_files $uri $uri/ /sysManage5/index.html;
            index  index.html index.htm;
         }
    location /api/ {  #对应后端
        proxy_pass http://backend; 
        proxy_read_timeout 90s;  #设置从后端服务器读取响应的超时时间为90秒。如果在此时间内未能读取到完整的响应,连接将会关闭。如果前端请求的数据过大,后端需要返回需要很久时间就需要把这个值调大一些
        proxy_connect_timeout 60s;  # 设置与后端服务器建立连接的超时时间为 60 秒。如果在此时间内未能建立连接,连接将会关闭
        proxy_send_timeout 60s;  # 设置向后端服务器发送请求的超时时间为 60 秒。如果在此时间内未能发送完整的请求,连接将会关闭。
    }

    error_page 404 /404.html;
}

4.root与alias区别,主要是去取资源的路径会有所变化

bash 复制代码
location /images/ {  
root /data/www/;  #请求http://example.com/images/index.html 会得到 /data/www/images/index.html
}
location /images/ {
    alias /data/www/; #请求#http://example.com/images/index.html 会得到 /data/www/index.html
}
相关推荐
那明眸似水11 分钟前
云原生项目三:Docker秒级启动NextCloud个人网盘存储办公系统
linux·运维·docker·云原生·容器
小南家的青蛙2 小时前
微服务体系下DevOps运维岗位面试方案设计
运维·面试·职场和发展·devops
知已难寻12 小时前
Docker 入门:容器技术与 Docker 基础
java·运维·服务器·docker·云原生·容器
默|笙12 小时前
【Linux网络】网络层协议 IP(1)理解报头、网段划分
linux·网络·tcp/ip
修己xj15 小时前
nslookup 使用指南:两种模式与常用查询技巧
linux
唠玖馆17 小时前
文件系统详解
linux·文件系统·ext2
GeW17 小时前
当Linux内核开始“确定性”,制造高端化才有了底层语法
linux
星恒随风18 小时前
MySQL 从零入门(三):表的约束详解
linux·服务器·数据库·笔记·mysql
Alluxio19 小时前
Alluxio + OCI:为 AI 工作负载实现亚毫秒访问延迟与可扩展吞吐
运维·数据库·人工智能·分布式·缓存·ai·语言模型
StarsGreen20 小时前
libva在intel平台上的前端流程简介
linux