server_names_hash_bucket_size 128; #指定服务器名称哈希表的框大小
client_header_buffer_size 32k;
large_client_header_buffers 4 128k; #以上两个是设定客户端请求的Header头缓冲区大小,对于cookie内容较大的请求,应增大改值。(400或414错误)
client_max_body_size 8m; #允许客户端请求的最大单文件字节数
client_body_buffer_size 32k; #缓冲区代理缓冲用户端请求的最大字节数,可以理解为保存到本地再传给用户
proxy_connect_timeout 600; #nginx跟后端服务器连接超时时间(代理连接超时)
proxy_read_timeout 600; #连接成功后,后端服务器响应时间(代理接收超时)
proxy_send_timeout 600; #后端服务器数据回传时间(代理发送超时)
proxy_buffer_size 32k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小
proxy_buffers 4 32k; #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置
proxy_busy_buffers_size 64k; #高负荷下缓冲大小(proxy_buffers*2)
proxy_temp_file_write_size 1024m; #设定缓存文件夹大小,大于这个值,将从upstream服务器传递请求,而不缓冲到磁盘
proxy_ignore_client_abort on; #不允许代理端主动关闭连接
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_proxied any; #前端是squid的情况下要加此参数,否则squid上不缓存gzip文件
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
server_tokens off;
#注:proxy_temp_path和proxy_cache_path指定的路径必须在同一分区
proxy_temp_path /cache/proxy_temp_path;
#设置Web缓存区名称为cache_one,内存缓存空间大小为200MB,1天没有被访问的内容自动清除,硬盘缓存空间大小为30GB。
proxy_cache_path /cache/proxy_cache_path levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=30g;
server {
listen 8012;
server_name localhost.net;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /var/www/nginx;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ .php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
proxy_pass http://127.0.0.1:8011;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
#include fastcgi_params;
}
#扩展名以.gif、.jpg、.css等结尾的静态文件缓存。
location ~ .*.(gif|jpg|jpeg|png|bmp|swf|js|css|mp3|mp4|flv|f4v|wmv|wma|mov)$
{
#如果后端的服务器返回502、504、执行超时等错误,自动将请求转发到upstream负载均衡池中的另一台服务器,实现故障转移。
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_cache cache_one; #进行缓存,使用Web缓存区cache_one
proxy_cache_valid 200 304 12h; #对不同的HTTP状态码设置不同的缓存时间
proxy_cache_valid 301 302 1m;
proxy_cache_valid any 1m;
proxy_cache_key
h
o
s
t
host
hosturi
i
s
a
r
g
s
is_args
isargsargs; #以域名、URI、参数组合成Web缓存的Key值,Nginx根据Key值哈希,存储缓存内容到二级缓存目录内
proxy_set_header Host
h
o
s
t
;
p
r
o
x
y
s
e
t
h
e
a
d
e
r
X
−
R
e
a
l
−
I
P
host; proxy_set_header X-Real-IP
host; proxysetheader X−Real−IP remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Accept-Encoding “none”; #设定proxy_set_header Accept-Encoding ‘’;
# (或是后台服务器关闭gzip),这样这台机器才
# 不会缓存被压缩的文件,造成乱码
#proxy_set_header Accept-Encoding “”; #这个也可
proxy_ignore_headers “Cache-Control” “Expires”; #这段配置加上后,proxy_cache就能支持后台设定的expires。
#proxy_pass http://127.0.0.1:8011; #反向代理
root /var/www/nginx;
expires 1h;
}
#设置只允许指定的IP或IP段才可以清除URL缓存。
location ~ /purge(/.*) {
allow 127.0.0.1;
allow 192.168.0.0/255;
allow all;
proxy_cache_purge cache_one $host
1
1
1is_argsKaTeX parse error: Expected 'EOF', got '}' at position 15: args; }̲ # d… {
proxy_pass http://127.0.0.1:8011;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
sl_protocols SSLv2 SSLv3 TLSv1;
[外链图片转存中…(img-2dxBEqtu-1726125587008)]
[外链图片转存中…(img-rL0Ax0bM-1726125587008)]
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。