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
}
相关推荐
EelBarb5 分钟前
seafile:ubuntu搭建社区版seafile12.0
linux·运维·ubuntu
Xam_d_LM8 分钟前
【Latex】Windows/Ubuntu 绘制 eps 矢量图通用方法(drawio),支持插入 Latex 数学公式
linux·ubuntu·科研·矢量图·drawio
402 Payment Required20 分钟前
serv00 ssh登录保活脚本-邮件通知版
运维·chrome·ssh
小柏ぁ25 分钟前
calico/node is not ready: BIRD is not ready: BGP not established with xxx
运维·docker·kubernetes
Mintimate1 小时前
云服务器 Linux 手动 DD 安装第三方 Linux 发行版:原理与实战
linux·运维·服务器
RussellFans1 小时前
Linux 环境配置
linux·运维·服务器
高冷的肌肉码喽2 小时前
Linux-进程间的通信
linux·运维·服务器
乖乖是干饭王2 小时前
Linux系统编程中的_GNU_SOURCE宏
linux·运维·c语言·学习·gnu
jekc8682 小时前
禅道18.2集成LDAP
linux·运维·服务器
weixin_434936282 小时前
k8S 命令
linux·容器·kubernetes