- 详解user www www;
- 定义 Nginx 运行的用户及组
- worker_processes 8; #[ debug | info | notice | warn | error | crit ]
- error_log /data1/logs/nginx_error.log crit; pid
- /usr/local/webserver/nginx/nginx.pid; #Specifies the value for maximum file descriptors that can be opened by this process.
- worker_rlimit_nofile 65535;
- 一个 nginx 进程打开的最多文件描述符数目,理论值应该是最多打开文件数(ulimit
- -n) nginx 进程数相除,与但是 nginx 分配请求并不是那么均匀,所以最好与 ulimit -n的值保持一致。
- # use [ kqueue | rtsig | epoll | /dev/poll | select | poll ];
- events use epoll; 参考事件模型
- worker_connections 65535; 每个进程最大连接数(最大连接=连接数 x 进程数) #设定 http 服务器
- http include
- mime.types; 文件扩展名与文件类型映射表
- default_type application/octet-stream; #默认文件类型
- #charset gb2312; 默认编码
- server_names_hash_bucket_size 128; #服务器名字的 hash 表大小
- client_header_buffer_size 32k; 上传文件大小限制
- large_client_header_buffers 4 32k; 设定请求缓
- client_max_body_size 8m; 设定请求缓
- sendfile on; #开启高效文件传输模式
- tcp_nopush
- on; 防止网络阻塞
- tcp_nodelay on; 防止网络阻塞
- keepalive_timeout 60; 超时时间
- #FastCGI 是为了改善网站的性能--减少资源占用,提高访问速度.有关 fastCGI 的
- 详细资料请参阅:http://www.fastcgi.com
- fastcgi_connect_timeout 300;
- fastcgi_send_timeout 300;
- fastcgi_read_timeout 300;
- fastcgi_buffer_size 64k;
- fastcgi_buffers 4 64k;
- fastcgi_busy_buffers_size 128k;
- fastcgi_temp_file_write_size 128k;
- gzip on;
- gzip_min_length 1k; #最小压缩文件大小
- gzip_buffers
- 4 16k; #压缩缓冲区
- gzip_http_version 1.0;
- #压缩版本(默认 1.1,前端为 squid2.5 使用 1.0
- gzip_comp_level 2; 压缩等级
- gzip_types
- text/plain application/x-javascript text/css application/xml;
- 压缩类型,默认就已经包含 text/html 所以下面就不用再写了,当然写上去的话,也
- 不会有问题,但是会有一个 warn
- gzip_vary on;
- #limit_zone crawler $binary_remote_addr 10m; server listen 80;
- server_name www.opendoc.com.cn
- index index.html index.htm index.php;
- root /data0/htdocs/opendoc;
- location ~ .*\.(php|php5)?$ #fastcgi_pass unix:/tmp/php-cgi.sock;
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- include fcgi.conf; #对图片缓存
- location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ expires 30d; #对 JS CSS 缓存
- location ~ .*\.(js|css)?$ expires 1h; #日志设定
- log_format access '$remote_addr - $remote_user [$time_local] "$request" '
- '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" $http_x_forwarded_for';
- #日志的格式
- access_log /data1/logs/access.log access;
- }
nginx判断手机移动设备用户的方法有两种方法一种是用语言进行判断,比如用php的 $_SERVER['User-Agent'] - <?php
- function is_mobile(){
- // returns true if one of the specified mobile browsers is detected
- $regex_match="/(nokia|iphone|android|motorola|^mot\-|softbank|foma|docomo|kddi|up\.browser|up\.link|";
- $regex_match.="htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|";
- $regex_match.="blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam\-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|";
- $regex_match.="symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte\-|longcos|pantech|gionee|^sie\-|portalmmm|";
- $regex_match.="jig\s browser|hiptop|^ucweb|^benq|haier|^lct|opera\s*mobi|opera\*mini|320x320|240x320|176x220";
- $regex_match.=")/i";
- return isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE']) or preg_match($regex_match, strtolower($_SERVER['HTTP_USER_AGENT']));
- }
- /*
- allow the user a way to force either the full or mobile versions of the site - use a GET parameter on requests:
- include likes to both versions of the site w/ the special force mode parameters, 'mobile' and 'full':
- <ahref="View'>http://www.php100.com/?mobile">View Mobile Site</a>
- <ahref="View'>http://www.php100.com/?full">View Full Site</a>
- Always check for 'mobile' or 'full' parameters before accounting for any User-Agent conditions:
- */
- if ($_GET['mobile']) {
- $is_mobile = true;
- }
- if ($_GET['full']) {
- $is_mobile = false;
- }
- if($is_mobile) {
- //it's a mobile browser, do something
- header("Location: http://wap.baidu.com");
- } else {
- //it's not a mobile browser, do something else
- header("Location: http://www.baidu.com");
- // or instead of a redirect, simply build html below
- }
- ?>
还有一种是用nginx的来判断- if ($http_user_agent ~* (mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)) {
- // 添加你需要处理的语句,比如rewrite等
- }
可能一些设备可能没有识别的,大家可以看分析日志,然后把 User-Agent的关键字写到if里面~ nginx的配置文件if语句是不支持“并且”和“或者”这样的多重条件判断的。在一些情况下,我们又需要if语句进行多个条件的判断,那么如何来实现呢?我们可以利用nginx的set语句设置变量的方法来解决。假设我们需要对 /123/ 路径进行rewrite,但同时要排除 /123/p_w_picpaths/ 路径不对该路径进行rewrite,可以采用下面的解决办法:- set $doRewrite "0";
- if ($request_uri ~ ^/123/) {
- set $doRewrite "1";
- }
- if ($request_uri ~ ^/123/p_w_picpaths/) {
- set $doRewrite "0";
- }
- if ($doRewrite = "1") {
- // do rewrite
- }
还有一个实例这个意思是 判断真是的ip,然后根据ip做一些操作~ 这里用的map映射- map $http_x_forwarded_for $deny_access {
- default 0;
- 1.2.3.4 1;
- 1.2.3.5 1;
- 1.2.3.6 1;
- }
- if ($deny_access = 1) {
- return 403;
- }
防盗链的一些个配置- location ~* \.(gif|png|jpg|bmp|swf|flv)$ {
- valid_referers none blocked www.ruifengyun.com ruifengyun.com;
- if ($invalid_referer) {
- return 403;
- }
- }
以上的例子可以实现扩展名为 gif,png,jpg,bmp,swf,flv的url防止被盗链。如果你需要其它的url防止被盗链,添加相应的后缀即可。也可以 把return 403 替换成 #rewrite ^/ http://ruifnegyun.com/404.jpg; 这样可以用另一种方法推广自己的网站nginx的限速的规则 配置简单,只需3行- http{
- ……
- limit_zone one $binary_remote_addr 10m;
- ……
- server {
- location / {
- ……
- limit_conn one 2;
- limit_rate 40k;
- }
- }
- }
意思是:limit_zone针对每个IP定义一个存储session状态的容器。这个示例中定义了一个名叫one的10m大小的容器,这个名字会在后面的limit_conn中使用。limit_conn指定每个访客只能建立两条链接,limit_rate限制每条链接的速度不超过40K。所以,以上配置限制用户访问此站点总速度上限为80K。 对于具有离线功能的智能手机应用程序,我正在为Xml文件创建单向文本同步。我希望我的服务器将增量/差异(例如GNU差异补丁)发送到目标设备。这是计划:Time=0Server:hasversion_1ofXmlfile(~800kiB)Client:hasversion_1ofXmlfile(~800kiB)Time=1Server:hasversion_1andversion_2ofXmlfile(each~800kiB)computesdeltaoftheseversions(=patch)(~10kiB)sendspatchtoClient(~10kiBtransferred)Cl
我正在编写一个包含C扩展的gem。通常当我写一个gem时,我会遵循TDD的过程,我会写一个失败的规范,然后处理代码直到它通过,等等......在“ext/mygem/mygem.c”中我的C扩展和在gemspec的“扩展”中配置的有效extconf.rb,如何运行我的规范并仍然加载我的C扩展?当我更改C代码时,我需要采取哪些步骤来重新编译代码?这可能是个愚蠢的问题,但是从我的gem的开发源代码树中输入“bundleinstall”不会构建任何native扩展。当我手动运行rubyext/mygem/extconf.rb时,我确实得到了一个Makefile(在整个项目的根目录中),然后当
我构建了两个需要相互通信和发送文件的Rails应用程序。例如,一个Rails应用程序会发送请求以查看其他应用程序数据库中的表。然后另一个应用程序将呈现该表的json并将其发回。我还希望一个应用程序将存储在其公共(public)目录中的文本文件发送到另一个应用程序的公共(public)目录。我从来没有做过这样的事情,所以我什至不知道从哪里开始。任何帮助,将不胜感激。谢谢! 最佳答案 无论Rails是什么,几乎所有Web应用程序都有您的要求,大多数现代Web应用程序都需要相互通信。但是有一个小小的理解需要你坚持下去,网站不应直接访问彼此
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server
刚入门rails,开始慢慢理解。有人可以解释或给我一些关于在application_controller中编码的好处或时间和原因的想法吗?有哪些用例。您如何为Rails应用程序使用应用程序Controller?我不想在那里放太多代码,因为据我了解,每个请求都会调用此Controller。这是真的? 最佳答案 ApplicationController实际上是您应用程序中的每个其他Controller都将从中继承的类(尽管这不是强制性的)。我同意不要用太多代码弄乱它并保持干净整洁的态度,尽管在某些情况下ApplicationContr
我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R
我正在使用RubyonRails3.0.9,我想生成一个传递一些自定义参数的link_toURL。也就是说,有一个articles_path(www.my_web_site_name.com/articles)我想生成如下内容:link_to'Samplelinktitle',...#HereIshouldimplementthecode#=>'http://www.my_web_site_name.com/articles?param1=value1¶m2=value2&...我如何编写link_to语句“alàRubyonRailsWay”以实现该目的?如果我想通过传递一些
我想这样组织C源代码:+/||___+ext||||___+native_extension||||___+lib||||||___(Sourcefilesarekeptinhere-maycontainsub-folders)||||___native_extension.c||___native_extension.h||___extconf.rb||___+lib||||___(Rubysourcecode)||___Rakefile我无法使此设置与mkmf一起正常工作。native_extension/lib中的文件(包含在native_extension.c中)将被完全忽略。
是否可以在应用程序中包含的gem代码中知道应用程序的Rails文件系统根目录?这是gem来源的示例:moduleMyGemdefself.included(base)putsRails.root#returnnilendendActionController::Base.send:include,MyGem谢谢,抱歉我的英语不好 最佳答案 我发现解决类似问题的解决方案是使用railtie初始化程序包含我的模块。所以,在你的/lib/mygem/railtie.rbmoduleMyGemclassRailtie使用此代码,您的模块将在