Linking

Capturing Life & Tech

  • 主页
  • 随笔
  • 关于我
所有文章 外链

Linking

Capturing Life & Tech

  • 主页
  • 随笔
  • 关于我

Nginx使用小结

阅读数:次 2019-07-08
字数统计: 403字   |   阅读时长≈ 1分
1
2
3
4
5
6
7
8
9
10
11
# 目录
- 1.初识
-- 1.1反向代理
-- 1.2正向代理
- 2.常用配置
-- 2.1负载均衡策略
-- 2.2Nginx 动静分离
--- 2.2.1动态server代理
--- 2.2.2静态文件HTTP代理
-- 2.3防盗链
- 3.参考

1.初识

1.1反向代理

代理服务器对外提供服务

1.2正向代理

代理客户端(个人pc)访问外网,如科学上网软件

2.常用配置

2.1负载均衡策略

  • 1.轮询:依次序访问,默认方式
  • 2.weight权重:自定义权重
  • 3.ip_hash:一直访问同一台服务器
  • 4.扩展自定义策略
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 默认轮询
upstream clusterName {
server 192.168.1.1:8081;
server 192.168.1.2:8081;
}

# weight
upstream clusterName {
server 192.168.1.1:8081 weight=1;
server 192.168.1.2:8081 weight=2; // 偏重
}

# ip_hash
upstream clusterName {
ip_hash;
server 192.168.1.1:8081;
server 192.168.1.2:8081;
}

具体请查看官方文档-load_balancing

2.2Nginx 动静分离

2.2.1动态server代理

正常配置http代理,走tomcat或其它server

1
2
3
4
5
6
7
8
9
10
11
12
13
14
upstream clusterName {  // 集群名称
server 192.168.1.1:8081;
server 192.168.1.2:8081;
}

server {
listen 80;
server_name abc.com;

location / {
proxy_pass http://clusterName; //必须与upstream配置集群名一致
}

}

2.2.2静态文件HTTP代理

1
2
3
4
5
6
7
8
9
# serve static files(css|js|image..)
location ~ ^/(images|javascript|js|css|flash|media|static)/ {
# windows
# root E:\svn\web;
# linux
root /home/statics/project-name;
access_log off;
# expires 30d;
}

2.3防盗链

1
2
3
4
5
6
7
8
9
#防盗链配置
location ~* \.(gif|jpg|png|jpeg|ico|css|js|pdf|txt|ttf|json|mp4|mov|html|avi|wmv) {
expires 30d;
valid_referers abc.com;
if ($invalid_referer) {
rewrite ^/ http://api.xxx.com;
#return 404;
}
}

3.参考

  • nginx.org
  • https://blog.csdn.net/u010039979/article/details/54345472
  • https://www.jianshu.com/p/3086fb860e57
  • 本文作者: Linking
  • 本文链接: https://linking.fun/2019/07/08/Nginx使用小结/
  • 版权声明: 版权所有,转载请注明出处!
  • nginx
  • CS

扫一扫,分享到微信

同一个IP(服务器)多个Tomcat产生session覆盖问题记录
413 too big,上传大文件,服务器连接被重置错误
  1. 1. 1.初识
    1. 1.1. 1.1反向代理
    2. 1.2. 1.2正向代理
  2. 2. 2.常用配置
    1. 2.1. 2.1负载均衡策略
    2. 2.2. 2.2Nginx 动静分离
      1. 2.2.1. 2.2.1动态server代理
      2. 2.2.2. 2.2.2静态文件HTTP代理
    3. 2.3. 2.3防盗链
  3. 3. 3.参考
© 2015-2026 Linking
GitHub:hexo-theme-yilia-plus by Litten
本站总访问量次 | 本站访客数人
  • 所有文章
  • 外链

tag:

  • weather
  • 需求
  • essay
  • basketball
  • olympic
  • nginx
  • APPScan
  • SQl盲注
  • xss
  • Ajax
  • ajax
  • ai
  • agent
  • openclaw
  • ccf
  • Nginx
  • HTML5
  • html5
  • hmtl5
  • sse
  • JavaScriptCore
  • Oracle
  • operation
  • Linux
  • deploy
  • Mac Office
  • markdown
  • ListView
  • GridView
  • MySQL
  • 慢查询
  • mongodb
  • 转置
  • thought
  • network
  • ubuntu
  • NetworkManager
  • RFKill
  • Netplan
  • avatar
  • cocoa
  • blog
  • Gitalk
  • container
  • macvlan
  • docker
  • oracle
  • cookie
  • patch
  • gitea
  • git
  • iOS
  • https
  • 多线程
  • bundle
  • 兼容性
  • HTTP
  • 绘图
  • cs
  • java
  • 效率
  • 快捷键
  • route
  • nodejs
  • pip
  • arcgis
  • arcgis 建模
  • 标识
  • redis
  • read
  • bookList
  • running
  • showdoc
  • disk
  • unit-test
  • D.Wade
  • thoughts
  • duoduo
  • Python
  • python
  • tomcat
  • 读书节
  • session
  • jdk
  • war
  • 加班
  • Android onclick事件监听
  • 正则
  • 手机品牌匹配
  • ntp
  • OpenLayers
  • Geoserver
  • wechat
  • 微信公众号
  • 爬虫
  • WeChat
  • 张靓颖
  • 动漫
  • vpn
  • PPT
  • MarkDown
  • plan
  • 朱赟
  • 极客时间专栏
  • 极客邦
  • 模块化
  • MVC
  • excel
  • NBA
  • kobe
  • team
  • crawler
  • 进度条
  • ssl
  • book
  • anti-stealing-link
  • Agentic Engineering
  • Vibe Coding
  • Software 3.0
  • Andrej Karpathy
  • LLM
  • Programming
  • complain

    缺失模块。
    1、请确保node版本大于6.2
    2、在博客根目录(注意不是yilia-plus根目录)执行以下命令:
    npm i hexo-generator-json-content --save

    3、在根目录_config.yml里添加配置:

      jsonContent:
        meta: false
        pages: false
        posts:
          title: true
          date: true
          path: true
          text: false
          raw: false
          content: false
          slug: false
          updated: false
          comments: false
          link: false
          permalink: false
          excerpt: false
          categories: false
          tags: true
    

  • GitHub Trending
  • OpenAI ChatGPT
  • Gitee码云
  • 简书
  • CSDN