Nginx正向加速方案集.docx

上传人:b****5 文档编号:6209084 上传时间:2023-01-04 格式:DOCX 页数:12 大小:18.67KB
下载 相关 举报
Nginx正向加速方案集.docx_第1页
第1页 / 共12页
Nginx正向加速方案集.docx_第2页
第2页 / 共12页
Nginx正向加速方案集.docx_第3页
第3页 / 共12页
Nginx正向加速方案集.docx_第4页
第4页 / 共12页
Nginx正向加速方案集.docx_第5页
第5页 / 共12页
点击查看更多>>
下载资源
资源描述

Nginx正向加速方案集.docx

《Nginx正向加速方案集.docx》由会员分享,可在线阅读,更多相关《Nginx正向加速方案集.docx(12页珍藏版)》请在冰豆网上搜索。

Nginx正向加速方案集.docx

Nginx正向加速方案集

Nginx正向加速方案集

方案一:

Nginx配置如下:

server

{

listen80;

server_name;

indexindex.htmlindex.htmindex.php;

root/home/wwwroot;

location/{

resolver222.166.225.132;

proxy_pass$scheme:

//$http_host$request_uri;

proxy_buffers2564k;

}

access_logoff;

}

注意事项:

1.不能有hostname

2.必须有resolver,即dns,即上面的x.x.x.x,换成当前机器的DNS服务器ip即可(查看dns方法cat/etc/resolv.conf代理使用)

3.$http_host和$request_uri是nginx系统变量,不要想着替换他们,保持原样就OK。

然后在浏览器中配置代理就可以了。

方案二.

Nginx配置如下:

server{

resolverx.x.x.x;

listen82;

location/{

proxy_passhttp:

//$http_host$request_uri;

}

}

注意项:

1.不能有hostname

2.必须有resolver,即dns,即上面的x.x.x.x,换成你们的DNS服务器ip即可

3.$http_host和$request_uri是nginx系统变量,不要想着替换他们,保持原样就OK。

查看dns方法

cat/etc/resolv.conf

代理使用

在需要访问外网的机器上执行以下操作之一即可:

1.exporthttp_proxy=http:

//yourproxyaddress:

proxyport

2.gedit~/.bashrc

exporthttp_proxy=http:

//yourproxyaddress:

proxyport

yourproxyaddress也就是你的Nginx服务器的ip了,proxyport就是上面配置中的82,可以根据自己的需要修改。

方案三

usernobodynobody;

worker_processes1;

error_loglogs/error.log;

pidlogs/nginx.pid;

events{

worker_connections1024;

useepoll;

}

http{

includemime.types;

default_typeapplication/octet-stream;

tcp_nopushon;

tcp_nodelayon;

keepalive_timeout65;

server{

resolver代理DNS;

listen8080;

log_formatmain'$msec$request_time$remote_addr$status$bytes_sent$request_methodhttp:

//$host$request_uri-DIRECT/$upstream_addr$upstream_http_content_type"$http_referer""$http_user_agent

"';

access_loglogs/daili.logmain;

location/{

proxy_passhttp:

//$http_host$request_uri;

}

}

}

方案四

nginx配置如下:

worker_processes4;

error_loglogs/error.logcrit;

worker_rlimit_nofile51200;

events{

worker_connections51200;

}

http{

includemime.types;

default_typeapplication/octet-stream;

sendfileon;

keepalive_timeout65;

server{

listen8080;

server_namelocalhost;

access_logoff;

client_header_buffer_size32k;

large_client_header_buffers4128k;

location/{

proxy_bufferingon;

proxy_buffer_size32k;

proxy_buffers864k;

proxy_busy_buffers_size128k;

resolver192.168.0.222;

proxy_set_headerHost$host;

proxy_set_headerX-Real-IP$host;

proxy_set_headerX-Forwarded-For$host;

proxy_passhttp:

//$host$request_uri;

log_formatmain'$remote_addr-$remote_user[$time_local]"$request"'

'$status$body_bytes_sent"$http_referer"'

'"$http_user_agent""$http_x_forwarded_for"';

access_log/data1/logs/proxyaccess.logcombined;

#//注意目录必须给守护nginx进程的用户;

}

error_page500502503504/50x.html;

location=/50x.html{

roothtml;

}

}

方案五

Nginx正向代理配置文件:

server{

resolver202.106.0.20;

resolver_timeout5s;

listen81;

location/{

proxy_pass$scheme:

//$host$request_uri;

proxy_set_headerHost$http_host;

proxy_buffers2564k;

proxy_max_temp_file_size0;

proxy_connect_timeout30;

proxy_cache_valid20030210m;

proxy_cache_valid3011h;

proxy_cache_validany1m;

}

}

二、Nginx正向代理配置说明:

1,配置DNS解析IP地址,比如北京dns,以及超时时间(5秒)。

resolver202.106.0.20;

resolver_timeout5s;

注意项

1.不能有hostname

2.必须有resolver,即dns,即上面的x.x.x.x,换成你们的DNS服务器ip即可

2,配置正向代理参数,均是由Nginx变量组成。

其中proxy_set_header部分的配置,是为了解决如果URL中带"."(点)后Nginx503错误。

proxy_pass$scheme:

//$host$request_uri;$http_host和$request_uri是nginx系统变量,不要想着替换他们,保持原样就OK。

proxy_set_headerHost$http_host;

3,配置缓存大小,关闭磁盘缓存读写减少I/O,以及代理连接超时时间。

proxy_buffers2564k;

proxy_max_temp_file_size0;

proxy_connect_timeout30;

4,配置代理服务器Http状态缓存时间。

proxy_cache_valid20030210m;

proxy_cache_valid3011h;

proxy_cache_validany1m;

三、不支持代理Https网站

因为Nginx不支持CONNECT,所以无法正向代理Https网站(网上银行,Gmail)。

方案6

userwwwwww;

worker_processes8;

error_log/usr/local/webserver/nginx/logs/nginx_error.logcrit;

pid/usr/local/webserver/nginx/nginx.pid;

#Specifiesthevalueformaximumfiledescriptorsthatcanbeopenedbythisprocess.

worker_rlimit_nofile65535;

events

{

useepoll;

worker_connections65535;

}

http

{

includemime.types;

default_typeapplication/octet-stream;

charsetutf-8;

server_names_hash_bucket_size128;

client_header_buffer_size32k;

large_client_header_buffers432k;

client_max_body_size300m;

sendfileon;

tcp_nopushon;

keepalive_timeout60;

tcp_nodelayon;

client_body_buffer_size512k;

proxy_connect_timeout5;

proxy_read_timeout60;

proxy_send_timeout5;

proxy_buffer_size16k;

proxy_buffers464k;

proxy_busy_buffers_size128k;

proxy_temp_file_write_size128k;

gzipon;

gzip_min_length1k;

gzip_buffers416k;

gzip_http_version1.1;

gzip_comp_level2;

gzip_typestext/plainapplication/x-javascripttext/cssapplication/xml;

gzip_varyon;

#注:

proxy_temp_path和proxy_cache_path指定的路径必须在同一分区

proxy_temp_path/data0/proxy_temp_dir;

#设置Web缓存区名称为cache_one,内存缓存空间大小为200MB,1天清理一次缓存,硬盘缓存空间大小为30GB。

proxy_cache_path/data0/proxy_cache_dirlevels=1:

2keys_zone=cache_one:

200minactive=1dmax_size=30g;

upstreambackend_server{

server192.168.8.43:

80weight=1max_fails=2fail_timeout=30s;

server192.168.8.44:

80weight=1max_fails=2fail_timeout=30s;

server192.168.8.45:

80weight=1max_fails=2fail_timeout=30s;

}

server

{

listen80;

server_name192.168.8.42;

indexindex.htmlindex.htm;

root/data0/htdocs/www;

location/

{

#如果后端的服务器返回502、504、执行超时等错误,自动将请求转发到upstream负载均衡池中的另一台服务器,实现故障转移。

proxy_next_upstreamhttp_502http_504errortimeoutinvalid_header;

proxy_cachecache_one;

#对不同的HTTP状态码设置不同的缓存时间

proxy_cache_valid20030412h;

#以域名、URI、参数组合成Web缓存的Key值,Nginx根据Key值哈希,存储缓存内容到二级缓存目录内

proxy_cache_key$host$uri$is_args$args;

proxy_set_headerHost$host;

proxy_set_headerX-Forwarded-For$remote_addr;

proxy_passhttp:

//backend_server;

expires1d;

}

#用于清除缓存,假设一个URL为http:

//192.168.8.42/test.txt,通过访问http:

//192.168.8.42/purge/test.txt就可以清除该URL的缓存。

location~/purge(/.*)

{

#设置只允许指定的IP或IP段才可以清除URL缓存。

allow127.0.0.1;

allow192.168.0.0/16;

denyall;

proxy_cache_purgecache_one$host$1$is_args$args;

}

#扩展名以.php、.jsp、.cgi结尾的动态应用程序不缓存。

location~.*\.(php|jsp|cgi)?

$

{

proxy_set_headerHost$host;

proxy_set_headerX-Forwarded-For$remote_addr;

proxy_passhttp:

//backend_server;

}

access_logoff;

}

}

方案7

userwwwwww;

worker_processes8;

error_log/usr/local/webserver/nginx/logs/nginx_error.logcrit;

pid/usr/local/webserver/nginx/nginx.pid;

#Specifiesthevalueformaximumfiledescriptorsthatcanbeopenedbythisprocess.

worker_rlimit_nofile65535;

events

{

useepoll;

worker_connections65535;

}

http

{

includemime.types;

default_typeapplication/octet-stream;

charsetutf-8;

server_names_hash_bucket_size128;

client_header_buffer_size32k;

large_client_header_buffers432k;

client_max_body_size300m;

sendfileon;

tcp_nopushon;

keepalive_timeout60;

tcp_nodelayon;

client_body_buffer_size512k;

proxy_connect_timeout5;

proxy_read_timeout60;

proxy_send_timeout5;

proxy_buffer_size16k;

proxy_buffers464k;

proxy_busy_buffers_size128k;

proxy_temp_file_write_size128k;

gzipon;

gzip_min_length1k;

gzip_buffers416k;

gzip_http_version1.1;

gzip_comp_level2;

gzip_typestext/plainapplication/x-javascripttext/cssapplication/xml;

gzip_varyon;

#注:

proxy_temp_path和proxy_cache_path指定的路径必须在同一分区

proxy_temp_path/data0/proxy_temp_dir;

#设置Web缓存区名称为cache_one,内存缓存空间大小为200MB,1天没有被访问的内容自动清除,硬盘缓存空间大小为30GB。

proxy_cache_path/data0/proxy_cache_dirlevels=1:

2keys_zone=cache_one:

200minactive=1dmax_size=30g;

upstreambackend_server{

server192.168.8.43:

80weight=1max_fails=2fail_timeout=30s;

server192.168.8.44:

80weight=1max_fails=2fail_timeout=30s;

server192.168.8.45:

80weight=1max_fails=2fail_timeout=30s;

}

server

{

listen80;

server_name192.168.8.42;

indexindex.htmlindex.htm;

root/data0/htdocs/www;

location/

{

#如果后端的服务器返回502、504、执行超时等错误,自动将请求转发到upstream负载均衡池中的另一台服务器,实现故障转移。

proxy_next_upstreamhttp_502http_504errortimeoutinvalid_header;

proxy_cachecache_one;

#对不同的HTTP状态码设置不同的缓存时间

proxy_cache_valid20030412h;

#以域名、URI、参数组合成Web缓存的Key值,Nginx根据Key值哈希,存储缓存内容到二级缓存目录内

proxy_cache_key$host$uri$is_args$args;

proxy_set_headerHost$host;

proxy_set_headerX-Forwarded-For$remote_addr;

proxy_passhttp:

//backend_server;

expires1d;

}

#用于清除缓存,假设一个URL为http:

//192.168.8.42/test.txt,通过访问http:

//192.168.8.42/purge/test.txt就可以清除该URL的缓存。

location~/purge(/.*)

{

#设置只允许指定的IP或IP段才可以清除URL缓存。

allow127.0.0.1;

allow192.168.0.0/16;

denyall;

proxy_cache_purgecache_one$host$1$is_args$args;

}

#扩展名以.php、.jsp、.cgi结尾的动态应用程序不缓存。

location~.*\.(php|jsp|cgi)?

$

{

proxy_set_headerHost$host;

proxy_set_headerX-Forwarded-For$remote_addr;

proxy_passhttp:

//backend_server;

}

access_logoff;

}

}

方案8

usernobodynobody;

worker_processes8;

error_loglogs/error.log;

pidlogs/nginx.pid;

events{

worker_connections5000;

useepoll;

}

http{

includemime.types;

default_typeapplication/octet-stream;

log_formatmain'[$time_local]$request_time"$remote_addr"$status$bytes_sent$request_methodhttp:

//$host$request_uri-DIRECT/$upstream_addr$upstream_http_content_type"$http_referer""$http_user_agent"';

access_loglogs/access.logmain;

sendfileon;

tcp_nopushon;

tcp_nodelayon;

keepalive_timeout65;

client_header_buffer_size128k;

large_client_header_buffers4256K;

gzipon;

gzip_min_length1000;

gzip_proxiedexpiredno-cacheno-storeprivateauth;

gzip_typestext/plainapplication/x-javascripttext/csstext/javascriptapplication/javascriptapplication/xml;

client_body_buffer_size512k;

proxy_connect_timeout5;

proxy_read_timeout60;

proxy_send_timeout5;

proxy_buffer_size16k;

proxy_buffers464k;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1