首页 > 系统相关 >nginx笔录

nginx笔录

时间:2022-11-19 23:02:47浏览次数:65  
标签:http 笔录 192.168 nginx html abucloud 72.128 com

Nginx

安装

安装教程

1.反向代理

  • 正向代理:比如kexue上网无法访问谷歌,需要一个代理服务器代理客户端请求谷歌,这个代理服务器就是正向代理
  • 反向代理:是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接的客户端,此时代理服务器对外就表现为一个反向代理服务器。隐藏了真正服务器的ip

正向代理其实是客户端的代理,帮助客户端访问其无法访问的服务器资源。反向代理则是服务器的代理,帮助服务器做负载均衡,安全防护等。

正向代理中,服务器不知道真正的客户端到底是谁,以为访问自己的就是真实的客户端。而在反向代理中,客户端不知道真正的服务器是谁,以为自己访问的就是真实的服务器。

http中配置以下内容

server {
    listen       80;		# 监听80端口
    server_name  abucloud.com;

    location /manager {
        proxy_pass http://192.168.72.128:8080;
    }

    location /user {
        proxy_pass http://192.168.72.128:8081;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

}
  1. 以访问abucloud.com以api开头的代理到 http://192.168.72.128:8080服务

    代理前的路径是:http://abucloud.com/api/getName?id=1

    代理后的路径是:http://192.168.72.128:8080/api/getName?id=1

  2. 以访问abucloud.com以dev开头的代理到 http://192.168.72.128:8081服务

    代理前的路径是:http://abucloud.com/api/getName?id=1

    代理后的路径是:http://192.168.72.128:8081/dev/getName?id=1

2.负载均衡

http中添加

upstream custom-myserver {
    server 192.168.72.128:8081;
    server 192.168.72.128:8082;
}

server {

    listen       80;
    server_name  abucloud.com;

    location /api {
        proxy_pass http://custom-myserver;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

}

以访问abucloud.com以api开头的代理到 负载均衡到http://192.168.72.128:8080、http://192.168.72.128:8080服务中,默认是轮询

3.动静分离

放置前端

server {

    listen       80;
    server_name  abucloud.com;
    charset utf-8;

    location / {
        root  /data/;
        index  index.html index.htm;
    }

}

所有访问abucloud.com路径的请求都会去linux系统/data/下找,也就是说/data/目录下存放前端打包资源

当访问abucloud.com实质上访问的是http://abucloud.com/index.html,如果/data/目录下没有index.html会报forbidden 403

案例1

upstream custom-myserver {
    server 192.168.72.128:8081;
    server 192.168.72.128:8082;
}

server {

    listen       80;
    server_name  abucloud.com;
    charset utf-8;

    location / {
        root  /data/;
        index  index.html index.htm;
    }

    location /api {
        proxy_pass http://custom-myserver;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

}

当用户输入http://abucloud.com时,会被转发访问/data/目录下的资源

当用户点击按钮触发发送ajax请求http://abucloud.com/api/xxx时,会被反向代理到http://custom-myserver,进行负载均衡到具体的服务中,可能是http://192.168.72.128:8081/api/xxx,也可能http://192.168.72.128:8082/api/xxx

标签:http,笔录,192.168,nginx,html,abucloud,72.128,com
From: https://www.cnblogs.com/party-abu/p/16907441.html

相关文章

  • nginx-config快捷配置项目
    Nginx是我们程序员绕不开的一个堪,对于不太熟悉的程序员来说,每次配置一次nginx都要去搜索一次配置,是不是你?这个开源项目给我们提供了一个可视化配置Nginx的方式,简直就......
  • nginx
    查看服务器上安装的nginx版本号,主要是通过nginx的-v或-V选项,查看方法如下图所示   -v显示nginx的版本。   -V显示nginx的版本,编译器版本和配置参数安......
  • 解决前后端分离业务中,前端访问后端404的Nginx配置。
    server{listen80;server_namelocalhost;root"E:/plan";location/{indexindex.phpindex.htmlerror/......
  • 第2-3-6章 打包批量下载附件的接口开发-文件存储服务系统-nginx/fastDFS/minio/阿里云
    目录5.6接口开发-根据文件id打包下载附件5.6.1接口文档5.6.2代码实现5.6.3接口测试5.7接口开发-根据业务类型/业务id打包下载5.7.1接口文档5.7.2代码实现5.7.3接口......
  • Ubuntu上如何用指令运行nginx,还有查看相应的进程
    1、运行nginxnginx是web服务器,要执行起来才能够看到相应的进程信息sudo ./nginx(注意是在什么目录下使用这个命令)./ 表示当前目录下,如果不加上./就找不到nginx../......
  • nginx做grpc端口的负载均衡
    最近需要部署一个grpc的服务,为了保证服务的qps达到标准,于是在一台机器上做多个server,这个时候得用到nginx做转发和负载安装:切记版本,试过1.12的,不可用#下载wgethttp://ng......
  • nginx做文件下载
    conf/nginx.conf中配置server{listen80;charsetutf-8;server_name服务器IP;root/data/Downloads/;autoindexon;......
  • Docker离线部署Nginx
    总体思路:在有网络的环境上制作Nginx的镜像包,导出并上传至无网络的环境上,启动Nginx即可。  在上一篇《无网环境DockerRpm离线安装》里面,已经在联网的机器上安装好了......
  • Docker安装nginx
    1、拉取nginx镜像并查看#docker搜索nignxdockersearchnginx#拉取nginx镜像--会从docker官方镜像中拉取dockerpullnginx#查看docker镜像dockerps-a2、运......
  • linux 安装nginx
    一、基础安装与启动//下载wgethttps://nginx.org/download/nginx-1.22.1.tar.gz//解压tar-zxvfnginx-1.22.1.tar.gzcdnginx-1.22.1//配置./configure//......