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
}
相关推荐
风静雪冷42 分钟前
grep命令要点、详解和示例
linux
我是哈哈hh1 小时前
【MySQL】在UBuntu环境安装以及免密码登录入门
linux·数据库·mysql·ubuntu
Lovyk1 小时前
基于 Ansible 与 Jinja2 模板的 LNMP 环境及 WordPress 自动化部署实践
linux·运维·服务器·自动化·ansible
LKAI.2 小时前
传统方式部署(RuoYi-Cloud)微服务
java·linux·前端·后端·微服务·node.js·ruoyi
知白守黑2672 小时前
Linux磁盘阵列
linux·运维·服务器
维尔切3 小时前
Linux中基于Centos7使用lamp架构搭建个人论坛(wordpress)
linux·运维·架构
tan77º4 小时前
【项目】分布式Json-RPC框架 - 项目介绍与前置知识准备
linux·网络·分布式·网络协议·tcp/ip·rpc·json
丘大梨4 小时前
QT 基础聊天应用项目文档
运维·数据库·系统架构
怀刃5 小时前
C# 内存监控怎么定位问题
运维
TPBoreas5 小时前
Jenkins启动端口修改失败查找日志
运维·服务器·jenkins