最近项目引入反向代理和缓存,熟悉了一下Squid、Apache、Valish、Nginx,根据项目实际进行选择,客观来说,采用Linux系统部署最好,也没有什么难度,但实际情况必须采用Windows系统(本着方案要结合现实的原则,研究要以Windows平台为主)。
一 Squid 配置:
在squid.conf配置文件末尾加上如下内容:
#show squid name
visible_hostname tg.squid-cache.jjtg.com
#cache_manager
cache_mgr xxx@abc.com #邮箱地址
#DNS查询
dns_testnames 192.168.45.45
#squid监听
http_port 7575 accel vhost vport
#后端站点
cache_peer 192.168.45.45 parent 7574 0 no-query originserver connect-timeout=180
#chache_memory
cache_mem 800 MB
cache_swap_low 90
cache_swap_high 95
#cache_dir::注意路径
cache_dir ufs E:/var/squid/tg/cache 100000 16 256
#cache_logs::注意路径
cache_log E:/var/squid/tg/logs/cache.log
logformat squid %ts.%03tu %6tr %>a %Ss/%03Hs %<st %rm %ru %un %Sh/%<A %mt
access_log E:/var/squid/tg/logs/access.log squid
cache_store_log E:/var/squid/tg/logs/store.log
#cache_log none
#access_log none
#cache_store_log none
pid_filename E:/var/squid/tg/logs/squid.pid
#cache runner
cache_effective_user squid
cache_effective_group squids
#隐藏不是必须的header
#2.x用header_access,3.x用reply_header_access
header_access ETag deny all
header_access Vary deny all
header_access Accept-Ranges deny all
header_access X-AspNet-Version deny all
header_access X-Powered-By deny all
#禁止缓存的文件
#hierarchy_stoplist -i \.aspx \.asmx \.ashx
acl NoneCache urlpath_regex -i \.aspx \.asmx \.ashx
no_cache deny NoneCache
#只允许本地PUGRE
acl AdminBoxes src 127.0.0.1 192.168.0.0/16
acl Purge method PURGE
http_access allow AdminBoxes Purge
http_access deny Purge
#squid ACL rules
#acl all src all
http_access allow all
#http_access deny all
二 Apache配置
在httpd.conf配置文件修改:
#增加监听端口:
Listen 7570
Listen 7574
#修改ServerName:
ServerName 192.168.45.45:7570
#用户自定义添加代理
#开启mod_proxy,mod_proxy_connect,mod_proxy_http
#代理拦截
<VirtualHost 192.168.45.45:7574>
ServerName 192.168.45.45:7574
ProxyPass / http://192.168.45.45:7573/
ProxyPassReverse / http://192.168.45.45:7573/
</VirtualHost>
#用户自定义配置静态文件的Expires:
<IfModule mod_headers.c>
#用户自定义去掉某些不必要的Header信息
#header unset Etag
#开启mod_expires
ExpiresActive On
ExpiresByType image/x-icon "access plus 1 months"
ExpiresByType application/x-javascript "access plus 1 weeks"
ExpiresByType text/css "access plus 1 weeks"
ExpiresByType image/gif "access plus 1 months"
ExpiresByType image/png "access plus 1 months"
ExpiresByType image/jpeg "access plus 1 months"
ExpiresByType application/x-shockwave-flash "access plus 1 months"
ExpiresByType video/x-flv "access plus 1 months"
ExpiresByType application/pdf "access plus 1 months"
#ExpiresByType text/html "access plus 1 weeks"
<FilesMatch "^(.*)\.(aspx|asmx|ashx)($|.*)">
Header unset Cache-Control
Header unset Expires
Header set Cache-Control "no-cache,no-store"
Header set Pragma "no-cache"
</FilesMatch>
</IfModule>
三 修改Apache连接数:1.修改httpd.conf文件
Include conf/extra/httpd-mpm.conf #去掉该行的注释,引用httpd-mpm.conf文件
2.修改/extra/httpd-mpm.conf#linux下:
#原:
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestPerClild 0
</IfModule>
#改为:
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
ServerLimit 1500
MaxClients 1000
MaxRequestsPerChild 0
</IfModule>
#windows:
#原:
<IfModule mpm_winnt_module>
ThreadsPerChild 150
MaxRequestsPerChild 0
</IfModule>
#改为:
<IfModule mpm_winnt_module>
ThreadsPerChild 500
MaxRequestsPerChild 5000
</IfModule>
4.改后,不能用restart重启,而要用stop停止,star启动