- 解决跨域
- 请求过滤
- 配置gzip
- 负载均衡
- 静态资源服务器
2、基本配置
// nginx.conf.js
events { // 配置nginx与用户的网络连接
}
http { // 配置代理、缓存、日志定义、配置第三方模块等
server { // 配置虚拟主机的参数
listen 8080,
server_name: www.baidu.com; //服务端域名
location / (请求路径) { // 配置请求路由
proxy_pass http://0.0.0.0:3000; // 设置代理
}
location = *.html {
root G:/My_Project/Server/index.html; // 获取静态文件,注意符号: /
}
location / {
rewrite ^.*$ / index.html redirect; //精准匹配url,并重定向
}
}
//负载均衡配置
server {
listen: 9001;
server_name: xxx.com;
location /api {
proxy_pass http://balanceServer;
}
}
upstream balanceServer { // 配置后端服务器的具体地址,负载均衡不可或缺
least_conn; // 配置连接策略
server 10.132.28.29:3030;
server 10.132.28.30:3030;
server 10.132.28.31:3030;
server 10.132.28.32:3030;
}
}
gzip on; // on/off(default) 开启或关闭
gzip_http_version 1.1; // 需要的最低http版本, 默认http/1.1
gzip_comp_level 5; // 压缩级别 1-9(default 1)
gzip_min_length 1000; // 允许压缩的最小字节, default 0
gzip_types text/csv text/xml text/css text/plain text/javascript application/javascript
application/x-javascript application/json application/xml;
//压缩的文件类型,default text/html
复制代码
3、内置全局变量
| 变量名 | 作用 |
|---|---|
| $host | 请求信息中的Host |
| $request_method | 请求类型 |
| $remote_addr | 客户端的IP地址 |
| $args | 请求参数 |
| $http_cookie | 客户端cookie信息 |
| $remote_port | 客户端端口 |
| $server_addr | 服务端地址 |
| $server_name | 服务端名称 |
| $server_port | 服务端端口 |
4、负载均衡策略
- 轮询策略(默认): 其中一台服务器出现延迟,影响所有分配到此服务器的用户;
- 最小连接数策略(least_conn): 优先分配给压力较小的服务器;
- 最快响应时间策略(fair):优先分配给响应时间最短的;
- 客户端ip绑定(ip_hash): 同一个ip的请求只分配给一台服务器,解决网页session共享问题。
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- Nuster:高性能缓存服务器
- 《高性能linux服务器构建实战》
- 高性能服务器架构思路,不仅是思路
- 高并发高性能服务器是如何实现的
- Exserver一款高性能的服务器软件
- 高性能Web服务器Nginx使用指南
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Think Python
Allen B. Downey / O'Reilly Media / 2012-8-23 / GBP 29.99
Think Python is an introduction to Python programming for students with no programming experience. It starts with the most basic concepts of programming, and is carefully designed to define all terms ......一起来看看 《Think Python》 这本书的介绍吧!