VPS侦探论坛

 找回密码
 注册
查看: 7067|回复: 12

nginx无法实现模块限制速度并发数

[复制链接]
发表于 2012-11-2 12:49:40 | 显示全部楼层 |阅读模式

nginx无法实现模块限制速度并发数
出现如下错误
  1. nginx: [emerg] unknown directive "log_format" in /usr/local/nginx/conf/nginx.conf:62
复制代码
nginx配置如下
  1. user  www www;worker_processes 1;error_log  /home/wwwlogs/nginx_error.log  crit;pid        /usr/local/nginx/logs/nginx.pid;#Specifies the value for maximum file descriptors that can be opened by this process.
  2. worker_rlimit_nofile 51200;events
  3. {
  4.   use epoll;
  5.   worker_connections 51200;
  6. }http
  7. {
  8.   include       mime.types;
  9.   default_type  application/octet-stream;  server_names_hash_bucket_size 128;
  10.   client_header_buffer_size 32k;
  11.   large_client_header_buffers 4 32k;
  12.   client_max_body_size 50m;  sendfile on;
  13.   tcp_nopush     on;  keepalive_timeout 60;  tcp_nodelay on;  fastcgi_connect_timeout 300;
  14.   fastcgi_send_timeout 300;
  15.   fastcgi_read_timeout 300;
  16.   fastcgi_buffer_size 64k;
  17.   fastcgi_buffers 4 64k;
  18.   fastcgi_busy_buffers_size 128k;
  19.   fastcgi_temp_file_write_size 256k;  gzip on;
  20.   gzip_min_length  1k;
  21.   gzip_buffers     4 16k;
  22.   gzip_http_version 1.0;
  23.   gzip_comp_level 2;
  24.   gzip_types       text/plain application/x-javascript text/css application/xml;
  25.   gzip_vary on;  # limit_zone   one  $binary_remote_addr  10m;  
  26.   server {
  27.     location /www/ {
  28.       limit_conn   one  2;
  29.       limit_rate 300k;
  30.     }
  31.   }
  32. }   #log format
  33.   log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
  34.              '$status $body_bytes_sent "$http_referer" '
  35.              '"$http_user_agent" $http_x_forwarded_for';include vhost/*.conf;
  36. }  
复制代码
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2012-11-3 07:53:55 | 显示全部楼层


# limit_zone   one  $binary_remote_addr  10m;

把#去掉好吧……?
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2012-11-3 16:53:27 | 显示全部楼层

我只能说配置文件已经让你该的面目全非了

只按错误提示log_format放错地方了,要在server前面
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2012-11-5 09:24:44 | 显示全部楼层



原帖由 licess 于 2012-11-3 16:53 发表
我只能说配置文件已经让你该的面目全非了

只按错误提示log_format放错地方了,要在server前面

对于下面的源码,该怎么写呢?

  1. user  www www;worker_processes 1;error_log  /home/wwwlogs/nginx_error.log  crit;pid        /usr/local/nginx/logs/nginx.pid;#Specifies the value for maximum file descriptors that can be opened by this process.
  2. worker_rlimit_nofile 51200;events
  3. {
  4.   use epoll;
  5.   worker_connections 51200;
  6. }http
  7. {
  8.   include       mime.types;
  9.   default_type  application/octet-stream;  server_names_hash_bucket_size 128;
  10.   client_header_buffer_size 32k;
  11.   large_client_header_buffers 4 32k;
  12.   client_max_body_size 50m;  sendfile on;
  13.   tcp_nopush     on;  keepalive_timeout 60;  tcp_nodelay on;  fastcgi_connect_timeout 300;
  14.   fastcgi_send_timeout 300;
  15.   fastcgi_read_timeout 300;
  16.   fastcgi_buffer_size 64k;
  17.   fastcgi_buffers 4 64k;
  18.   fastcgi_busy_buffers_size 128k;
  19.   fastcgi_temp_file_write_size 256k;  gzip on;
  20.   gzip_min_length  1k;
  21.   gzip_buffers     4 16k;
  22.   gzip_http_version 1.0;
  23.   gzip_comp_level 2;
  24.   gzip_types       text/plain application/x-javascript text/css application/xml;
  25.   gzip_vary on;
  26.                 limit_zone  crawler  $binary_remote_addr  50m;
  27.   
  28.                 #log format
  29.   log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
  30.              '$status $body_bytes_sent "$http_referer" '
  31.              '"$http_user_agent" $http_x_forwarded_for';  include vhost/*.conf;
  32. }
复制代码
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2012-11-5 14:31:54 | 显示全部楼层

顶上去看看
军哥怎么不说下

军哥运维代购:http://shop63846532.taobao.com/

发表于 2012-11-5 15:56:51 | 显示全部楼层
 楼主| 发表于 2012-11-5 19:53:37 | 显示全部楼层

回复 6# 的帖子


可是文章中并没有提及到怎么限制速度,只是限制了并发数
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2012-11-5 20:09:55 | 显示全部楼层

回复 6# 的帖子


安装提示在后面加了limit_conn oneip 20;提示这个
nginx: [emerg] zero size shared memory zone "oneip"
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2012-11-5 20:13:05 | 显示全部楼层

回复 7# 的帖子


加个 limit_rate ××k;不就行了

军哥运维代购:http://shop63846532.taobao.com/

 楼主| 发表于 2012-11-6 09:44:35 | 显示全部楼层

回复 9# 的帖子




不行,提示如下
Stoping LNMP...
Nginx program is stop
Shutting down php_fpm . done
PHP-FPM program is stop
MySQL program is not runing!
Starting LNMP...
nginx: [emerg] zero size shared memory zone "oneip"
Nginx start successfully!
Starting php_fpm  done
PHP-FPM start successfully!
Starting MySQL SUCCESS!
MySQL start successfully!
 楼主| 发表于 2012-11-6 09:47:38 | 显示全部楼层

回复 9# 的帖子


还是不行啊
这样的话会出错,但是不知道该怎么处理
发表于 2012-11-6 10:30:43 | 显示全部楼层

肯定是server段前没加上limit_zone  oneip  $binary_remote_addr  10m;
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2012-11-6 13:32:03 | 显示全部楼层
已经搞定了
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-9-23 23:27 , Processed in 0.030023 second(s), 17 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表