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
}
相关推荐
平行云PVT8 小时前
数字孪生信创云渲染技术解析:从混合信创到全国产化架构
linux·unity·云原生·ue5·图形渲染·webgl·gpu算力
xdscode8 小时前
Linux云服务器安装openclaw,并对接飞书通道
linux·服务器·飞书·openclaw
Percep_gan9 小时前
Linux中安装Redis,很详细
linux·运维·redis
七七powerful9 小时前
运维养龙虾--AI 驱动的架构图革命:draw.io MCP 让运维画图效率提升 10 倍,使用codebuddy实战
运维·人工智能·draw.io
枕书9 小时前
实战记录:如何使用 Docker 一键部署长亭 PandaWiki 智能知识库
运维·docker·容器
2401_877274249 小时前
从匿名管道到 Master-Slave 进程池:Linux 进程间通信深度实践
linux·服务器·c++
feng_you_ying_li10 小时前
linux之用户的权限详解(4)
linux·运维·服务器
二进制person11 小时前
JavaEE初阶 --网络编程
linux·服务器·网络
Cyber4K11 小时前
【妙招系列】Harbor 镜像私有仓库搭建手册
linux·云原生·容器
Irissgwe12 小时前
进程间通信
linux·服务器·网络·c++·进程间通信