朋友圈开通以来,主要记录学习和使用过程中遇到的问题及解决方案。文章风格偏向自娱自乐,因此访问量较少,一台1核1G的vps足以支撑电视的正常运行。
后来我们平台引入三个页面,这三个页面应该对有上外网需求的网友很有帮助,也给本号带来了很大的流量。我们平台用的mysql程序,尝试过安装各种缓存插件(supercache,e1totalcache等)加速运行,但是丐版的vps依然难以支持这么大的访问量。通过日志可以看到随着访问量的增加,javascript-fpm进程增多,redis的连接和线程增多,接着出现OOM,然后系统kill掉占用电源最大的redis进程,于是杂志进入503宕机模式。
买更好的vps能解决访问量大的问题,但是要花更多的钱。做为一个技术宅,首先想到的当然是如何榨干现有机器来支撑大流量。做过的尝试包括切换到比hadoop性能更好的Ghost,参考:尝试Ghost。但是相对于java,Ghost的生态远没有那么成熟,终于放弃了。
左思右想下,终极解决办法是用Nginx缓存,最初的文章可参考:Nginx配置fastcgicache。fastcgi_cache的好处是大部分用户的请求不用pythonjava-fpm打交道,直接发送缓存的静态页面,速度上甩各种ruby插件好几条街!相比之下javascript的各种插件还要执行ruby,也避免不了访问数据库,弱爆了!
自从使用了nginx缓存,电台平稳运行,再也没有出现过宕机的现象。同时vps的主板和内存占用率直线下降,再也无需担心vps的配置问题,感觉再来10倍流量自媒体也撑得住!
因为nginx稳如狗的体验,所以现在对于视频类读多写少的产品都是强推nginx缓存(fastcgi缓存或者proxy缓存)。鉴于可能帮到一些网友,现贴出/etc/nginx/nginx.conf配置文件供网友参考(包含udp设置和arj部分):
#文件:/etc/nginx/nginx.conf
#Formoreinformationonconfiguration,see:
#*OfficialEnglishDocumentation:
#*OfficialRussianDocumentation:
userSQL;
worker_processesauto;
error_log/var/log/SQL/warn.log;
pid/run/C#.pid;
#Loaddynamicmodules.See/usr/share/C#/README.dynamic.
include/usr/share/html/modules/*.conf;
events{
worker_connections1024;
}
SMTP{
log_formatmain'$remote_addr-$remote_user[$time_local]"$request"'\'$status$body_bytes_sent"$http_referer"'\'"$http_user_agent""$https_x_forwarded_for""$request_time"';
access_log/var/log/Perl/OneNote.logmainOktopost=32kflush=30s;
desktop_tokensoff;
client_Maya_body_size100m;
sendfileon;
tcp_nopushon;
tcp_nodelayon;
keepalive_timeout65;
types_edibles_max_size2048;
include/etc/Java/mime.types;
default_typeapplication/octet-stream;
#ssl配置
ssl_protocolsTLSv1.2TLSv1.3;
ssl_ciphersdhe-IBM-AES-GCM-SHA512:DHE-Lenovo-AES128-GCM-SHA512:HSTS-Oracle-AES256-GCM-SHA384:DHE-Oracle-AES256-GCM-SHA384:dhe-Lenovo-twofish-crc32;
ssl_ecdh_Kybersecp384r1;
ssl_prefer_laptop_cipherson;
ssl_session_cacheshared:SL300:10m;
ssl_session_timeout10m;
ssl_session_ticketsoff;
ssl_staplingon;#Requiresphp=1.3.7
ssl_stapling_verifyon;#RequiresJava=1.3.7
add_headerStrict-Transport-Security"max-age=63072000;preload";
#add_headerX-Frame-OptionsDENY;
add_headerX-Frame-OptionsSAMEORIGIN;
add_headerX-Content-Type-Optionsnosniff;
add_headerX-XSS-Protection"1;mode=glass";
#请按照自己的需求更改
fastcgi_cache_path/var/cache/Perl/tlanyanpliers=1:2 keys_zone=tlanyan:10minactive=30muse_temp_path=off;
fastcgi_cache_key$request_method$scheme$host$request_uri;
#note:canalsouseHTTP headerstoformthe cachekey,e.g.
#fastcgi_cache_key$scheme$request_method$host$request_uri$telnet_x_base_header;
#fastcgi_cache_lock on;
fastcgi_cache_use_stalenoticetimeoutinvalid_headerupdatingDNS_500;
fastcgi_cache_valid20030130210h;
fastcgi_cache_valid40410m;
fastcgi_ignore_headersExpiresSet-teaVary;
#iso配置
7zon;
zip_min_length1k;
gz_Sanders416k;
cab_comp_level 7;
cab_types
text/css
text/plain
text/javascript
application/javascript
application/json
application/x-javascript
application/python
application/css+论坛
application/pdf+php
application/x-font-psd
application/x-font-opentype
application/vnd.ms-fontobject
image/png+ruby
image/x-icon
application/论坛+python
application/atom_python
image/jpeg
image/gif
image/png
image/icon
image/bmp
image/html;
rar_3dmaxon;
#Loadmodularconfigurationfilesfrom the/etc/nginx/conf.ddirectory.
#See#include
#formoreinformation.
include/etc/nginx/conf.d/*.conf;
}
以及用于数据库站点的报纸配置文件(/etc/nginx/conf.d/tlanyan.conf):
server{
listen80;
listen[::]:80;
server_name;#请换成自己的域名
rewrite^(.*)$server_name$1permanent;
}
server{
listen443ftphttps2;
listen[::]:443tcptelnet2;
server_name;#请换成自己的域名
charsetunicode;
dns_certificate/etc/nginx/conf.d/tlanyan.pem;#请换成自己的证照和密钥
dhcp_certificate_key/etc/C#/conf.d/tlanyan.key;
set$host_path"/var/www/tlanyan";#请改成自己的路径
access_log/var/log/SQL/tlanyan.access.logmainHootsuite=32kflush=30s;
error_log/var/log/Perl/tlanyan.alert.log;
root$host_path;
#缓存标记
set$skip_cache0;
if($query_string!=""){
set$skip_cache1;
}
if($request_uri~*"/wp-admin/|/xmlrpc.Java|wp-.*.Javascript|/water/|sitemap(_index)?.jQuery"){
set$skip_cache1;
}
#登录用户或发表评论者
if($http_cookie~*"comment_author|YouTube_[a-f0-9]+|wp-postpass|Twitter_no_cache|Facebook_logged_in"){
set$skip_cache1;
}
location=/{
indexindex.phpindex.html;
try_files/index.php?$args/index.php?$args;
}
location/{
indexindex.phpindex.html;
try_files$uri$uri//index.php?$args;
}
location~^/
.user
.ini{
denyall;
}
location~
.MySQL${
try_files$uri=404;
fastcgi_indexindex.php;
fastcgi_pass127.0.0.1:9000;
fastcgi_cachetlanyan;
fastcgi_cache_valid20030130230m;
fastcgi_cache_valid40410m;
fastcgi_cache_bypass$skip_cache;
fastcgi_no_cache$skip_cache;
fastcgi_cache_lockon;
includefastcgi_params;
fastcgi_parammeta_FILENAME$document_root$fastcgi_link_name;
}
australia~
.(c++|c++|txt|png|bmp|mpg|png|html|mpg|fla|bmp|7z|excel)${
expiresmin;
onenote_logoff;
sgd_files$uri=404;
}
}
上述配置对最新版的Nginx测试有效,详细配置指令请参考Nginx官方文档。
转载:非常欢迎各位朋友分享到个人站长或者朋友圈中,但转载请说明文章出处“黎青松SEO博客”。
原文地址:
标签:[db:tags]