0%

Nginx 反向代理 配置

本文介绍了如何使用 Nginx 反向代理自己站点进行加速的。

目前我开了一个 AWS 的 AWS Global Accelerator 服务,价格还算可以。有 CDN 加速效果。

Nginx 反向代理配置文件参考

在 Nginx 文件夹下创建 conf 文件,用于反代。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
proxy_cache_path  /data/cdn/sites/default.itnote.me/proxy_cache levels=1:2 keys_zone=proxy_cache_zone_of_site_default.itnote.me:10m max_size=5g inactive=7d;

server {
listen 80;
server_name default.itnote.me;
keepalive_timeout 75s;
keepalive_requests 100;
access_log /data/cdn/sites/default.itnote.me/log/nginx/access.log;
error_log /data/cdn/sites/default.itnote.me/log/nginx/error.log;
gzip on;
gzip_comp_level 6;
gzip_min_length 1k;
gzip_types text/plain text/css text/xml text/javascript text/x-component application/json application/javascript application/x-javascript application/xml application/xhtml+xml application/rss+xml application/atom+xml application/x-font-ttf application/vnd.ms-fontobject image/svg+xml image/x-icon font/opentype;

location / {
proxy_pass $scheme://192.168.1.1:$server_port;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
client_max_body_size 1m;
proxy_cache_key $scheme$host$request_uri;
proxy_cache proxy_cache_zone_of_site_default.itnote.me;
proxy_cache_valid 200 301 302 7d;
proxy_cache_valid any 7d;
proxy_cache_min_uses 1;
proxy_cache_methods GET HEAD;
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
proxy_cache_revalidate on;
proxy_cache_lock on;
proxy_cache_lock_timeout 6s;
}
}