web服务器
第一页 1 2 3 下页 最后页 [ 显示模式: 摘要 | 列表 ]

nginx出现502有很多原因,但大部分原因可以归结为资源数量不够用,也就是说后端php-fpm处理有问题,nginx将正确的客户端请求发给了后端的php-fpm进程,但是因为php-fpm进程的问题导致不能正确解析php代码,最终返回给了客户端502错误。

服务器出现502的原因是连接超时 我们向服务器发送请求 由于服务器当前链接太多,导致服务器方面无法给于正常的响应,产生此类报错

因此如果你服务器并发量非常大,那只能先增加机器,然后按以下方式优化会取得更好效果;但如果你并发不大却出现502,一般都可以归结为配置问题,脚本超时问题。

一、php-fpm进程数不够用

使用 netstat -napo |grep "php-fpm" | wc -l 查看一下当前fastcgi进程个数,如果个数接近conf里配置的上限,就需要调高进程数。

但也不能无休止调高,可以根据服务器内存情况,可以把php-fpm子进程数调到100或以上,在4G内存的服务器上200就可以。


二、调高调高linux内核打开文件数量

可以使用这些命令(必须是root帐号)

C#代码
  1. echo 'ulimit -HSn 65536' >> /etc/profile  
  2. echo 'ulimit -HSn 65536' >> /etc/rc.local  
  3. source /etc/profile  

三、脚本执行时间超时

 

如果脚本因为某种原因长时间等待不返回 ,导致新来的请求不能得到处理,可以适当调小如下配置。

nginx.conf里面主要是如下

C#代码
  1. fastcgi_connect_timeout 300;  
  2. fastcgi_send_timeout 300;  
  3. fastcgi_read_timeout 300;  

php-fpm.conf里如要是如下

C#代码
  1. request_terminate_timeout = 10s  

四、缓存设置比较小

 

修改或增加配置到nginx.conf

C#代码
  1. proxy_buffer_size 64k;  
  2. proxy_buffers  512k;  
  3. proxy_busy_buffers_size 128k;  

五、 recv() failed (104: Connection reset by peer) while reading response header from upstream

 

可能的原因机房网络丢包或者机房有硬件防火墙禁止访问该域名

但最重要的是程序里要设置好超时,不要使用php-fpm的request_terminate_timeout,

最好设成request_terminate_timeout=0;

因为这个参数会直接杀掉php进程,然后重启php进程,这样前端nginx就会返回104: Connection reset by peer。这个过程是很慢,总体感觉就是网站很卡。

C#代码
  1. May 01 10:50:58.044162 [WARNING] [pool www] child 4074, script '/usr/local/nginx/html/quancha/sameip/detail.php' execution timed out (15.129933 sec), terminating  
  2. May 01 10:50:58.045725 [WARNING] [pool www] child 4074 exited on signal 15 SIGTERM after 90.227060 seconds from start  
  3. May 01 10:50:58.046818 [NOTICE] [pool www] child 4082 started  

说一千道一万最重要的就是程序里控制好超时,gethostbyname、curl、file_get_contents等函数的都要设置超时时间。

 

另一个就是多说,这个东西是增加了网站的交互性,但是使用的多了反应就慢了,如果你网站超时且使用了多说是,可以关闭它。

php-fpm.conf max_children 和 max_requests配置:

pm = static

假如使用静态 pm.max_children这个参数会起作用,其余不会。动态反之。

2G内存pm.max_children大概开启50左右,按照实际情况来调优,这个是很必要的。

========================================================

max_children是PHP-FPM Pool 最大的子进程数,他数值取决于你的服务器内存。 假设你打算给10G内存给当前配置的PHP-FPM Pool,一般一个PHP请求占用内存10M-40M,我们按站点每个PHP请求占用内存25M,这样max_children = 10G/25M = 409。所以,这个值可以根据情况算出来

max_requests是每个子进程重生之前处理的请求数, 默认值为unlimited(默认为1024),可以设置小一点(如500左右),这样可以避免内存泄露带来的问题

Nginx代理过程,将业务服务器请求数据缓存到本地文件,再将文件数据转发给请求客户端。高并发的客户端请求,必然要求服务器文件句柄的并发打开限制。使用ulimit命令(ulimit -n),查看Linux系统文件句柄并发限制,默认是1024,我们可以改为65535(2 的 16 次方,这是系统端口的极限)。修改的方法为:修改系统文件/etc/security/limits.conf,添加如下信息,并重新启动系统生效。

C#代码
  1. * soft   nofile  65535  
  2.   
  3. * hard   nofile  65535  

然后在Nginx配置文件中,把文件限制及连接数信息改为65535:

C#代码
  1. worker_rlimit_nofile 65535;  
  2. events {  
  3.     use epoll;  
  4.     worker_connections  65535;  
  5. }  

 

NGINX 重写规则

[不指定 2016/11/11 12:06 | by 刘新修 ]

nginx rewrite 实现二级域名跳转

当访问http://abc.test.com跳转到http://www.test.com/test/abc/
方法一:
这种方法浏览器地址会变www.test.com/test/abc
实现访问如下:
server { 
        listen 80; 
        server_name www.test.com; 
        location / { 
                root /data/test; 
                index index.html; 
        } 
 
 
server { 
        listen 80; 
        server_name *.test.com; 
        if ( $http_host ~* "^(.*)\.test\.com$") { 
                set $domain $1; 
                rewrite ^(.*) http://www.test.com/test/$domain/ break; 
        } 
}
方法二、
 
当访问http://abc.test.com跳转到http://www.test.com/test/abc/
server {
        listen 80; 
        server_name *.test.com; 
        root /usr/local/www; 
        #这是里可以加多个目录,如果不加目录,会无法访问到abc.test.com/目录下的文件,如图片目录/images
        location ~ ^/(test|images|styles)/ 
        { 
                proxy_redirect        off; 
                proxy_set_header    Host   www.test.com; 
                proxy_pass      http://192.168.1.2:8080; 
        } 
        location / { 
                set $domain default; 
                if ( $http_host ~* "^(.*)\.test\.com$") { 
                        set $domain $1; 
                } 
                rewrite ^/(.*)    /test/$domain/$1 last; 
        } 
        access_log off;
}
 
rewrite命令
nginx的rewrite相当于apache的rewriterule(大多数情况下可以把原有apache的rewrite规则加上引号就可以直接使用),它可以用在server,location 和IF条件判断块中,命
 
令格式如下:
rewrite 正则表达式 替换目标 flag标记
flag标记可以用以下几种格式:
last - 基本上都用这个Flag。
break - 中止Rewirte,不在继续匹配
redirect - 返回临时重定向的HTTP状态302
permanent - 返回永久重定向的HTTP状态301
例如下面这段设定nginx将某个目录下面的文件重定向到另一个目录,$2对应第二个括号(.*)中对应的字符串:
 
location /download/ {
        rewrite ^(/download/.*)/m/(.*)\..*$ $1/nginx-rewrite/$2.gz break;
}
 
nginx重定向的IF条件判断
在server和location两种情况下可以使用nginx的IF条件判断,条件可以为以下几种:
正则表达式
 
如:
匹配判断
~ 为区分大小写匹配; !~为区分大小写不匹配
~* 为不区分大小写匹配;!~为不区分大小写不匹配
 
就是当用户输入 www.a.com.cn 自动跳转到www.a.com 这个域名:
 
rewrite ^/(.*)$ http://www.a.com/$1 permanent; 或者cname
例如下面设定nginx在用户使用ie的使用重定向到/nginx-ie目录下:
if ($http_user_agent ~ MSIE) {
        rewrite ^(.*)$ /nginx-ie/$1 break;
}
文件和目录判断
-f和!-f判断是否存在文件
-d和!-d判断是否存在目录
-e和!-e判断是否存在文件或目录
-x和!-x判断文件是否可执行
 
例如下面设定nginx在文件和目录不存在的时候重定向:
if (!-e $request_filename) {
        proxy_pass http://127.0.0.1;
}
 
return
返回http代码,例如设置nginx防盗链:
location ~* \.(gif|jpg|png|swf|flv)$ {
        valid_referers none blocked www.jefflei.comwww.leizhenfang.com;
        if ($invalid_referer) {
                return 404;
        }
}
 
记一正则,匹配非某单词
由于要rewrite一个地址从
/mag/xx/xxx/ -> /m/xxx
但原先 /mag/xx/more/ 要保留
这就得写一个比较奇特的正则了,尝试了比较多的写法也没成功
 
最先想的是:
 
location ~* ^/mag/[^/]+/[^(more)]+/ {
  rewrite ^/mag/[^/]+/(.*) /m/$1 permanent;
}
 
 
[]的写法并不凑效,里面是匹配单个字符的,这样无效,匹配不了
 
还是小范同学不错,研究的深入,提供了非某单词的写法 (?!more)
 
location ~* ^/mag/[^/]+/(?!more)([^/]+)/ {
  rewrite ^/mag/[^/]+/(.*) /m/$1 permanent;
}
 
 
这个写法勉强可以应付了,后面的匹配单元虽说还不完美,但也能够对付我的所有需求内容了。
有需要的可以参考此写法。
 
引用
 
常用分组语法
 
捕获
(exp) 匹配exp,并捕获文本到自动命名的组里 
(?exp) 匹配exp,并捕获文本到名称为name的组里,也可以写成(?'name'exp) 
(?:exp) 匹配exp,不捕获匹配的文本,也不给此分组分配组号 
 
零宽断言 
(?=exp) 匹配exp前面的位置 
(?<=exp) 匹配exp后面的位置 
(?!exp) 匹配后面跟的不是exp的位置 
(?
为何要使用301重定向
在网站建设中需要网页重定向的情况很多:如网页目录结构变动,网页重命名、网页的扩展名改变、网站域名改变等。如果不做重 定向,用户的收藏和搜索引擎数据库中的旧地址只能让访客得到一个404错误信息页面,访问流量白白丧失。不仅如此,之前该页面的一切积累(比如PR值)就 都白费了。
301重定向不仅能使页面实现自动跳转,对于搜索引擎来说,也可能可以传递PR值。
nginx重定向规则详细介绍
http://www.jefflei.com/post/1015.html
rewrite命令
nginx的rewrite相当于apache的rewriterule(大多数情况下可以把原有apache的rewrite规则加上引号就可以直接使用),它可以用在server,location 和IF条件判断块中,命令格式如下:
rewrite 正则表达式 替换目标 flag标记
flag标记可以用以下几种格式:
last – 基本上都用这个Flag。
break – 中止Rewirte,不在继续匹配
redirect – 返回临时重定向的HTTP状态302
permanent – 返回永久重定向的HTTP状态301
例如下面这段设定nginx将某个目录下面的文件重定向到另一个目录,$2对应第二个括号(.*)中对应的字符串:
location /download/ {
rewrite ^(/download/.*)/m/(.*)\..*$ $1/nginx-rewrite/$2.gz break;
}
nginx重定向的IF条件判断
在server和location两种情况下可以使用nginx的IF条件判断,条件可以为以下几种:
正则表达式
如:
匹配判断
~  为区分大小写匹配; !~为区分大小写不匹配
 ~* 为不区分大小写匹配;!~为不区分大小写不匹配
例如下面设定nginx在用户使用ie的使用重定向到/nginx-ie目录下:
if ($http_user_agent ~ MSIE) {
rewrite ^(.*)$ /nginx-ie/$1 break;
}
文件和目录判断
  -f和!-f判断是否存在文件
 -d和!-d判断是否存在目录
 -e和!-e判断是否存在文件或目录
 -x和!-x判断文件是否可执行
例如下面设定nginx在文件和目录不存在的时候重定向:
if (!-e $request_filename) {
proxy_pass http://127.0.0.1/;
}
return
返回http代码,例如设置nginx防盗链:
location ~* \.(gif|jpg|png|swf|flv)$ {
valid_referers none blocked http://www.jefflei.com/ http://www.leizhenfang.com/;
if ($invalid_referer) {
return 404;
}
}
set
设置nginx变量
 
301重定向方法
进行了301重定向,把www .jefflei.com和jefflei.com合并,并把之前的域名也一并合并. 有两种实现方法,第一种方法是判断nginx核心变量host(老版本是http_host):
server {
server_name www.jefflei.com jefflei.com ;
if ($host != 'www.jefflei.com' ) {
rewrite ^/(.*)$ http://www.jefflei.com/$1 permanent;
}
...
}
第二种方法:
server {
server_name jefflei.com;
rewrite ^/(.*) http://www.jefflei.com/$1 permanent;
}
测试了第一种方法ok,这两种方法中, permanent是关键,详细说明见nginx重定向规则说明。
last – 基本上都用这个Flag。
break – 中止Rewirte,不在继续匹配
redirect – 返回临时重定向的HTTP状态302
permanent – 返回永久重定向的HTTP状态301
好了,现在可以检查结果,这里可以看返回的HTTP头信息:
http://www.seoconsultants.com/tools/headers.asp
第二种方法没有测试成功...
 
测试是否定向成功
http://qinfy.net/301-redirect-for-nginx/
输入指令~
/usr/local/nginx/sbin/nginx -t
提示:
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
configuration file /usr/local/nginx/conf/nginx.conf test is successful
测试成功~ 重启nginx~ 输入指令~
/usr/local/nginx/sbin/nginx -s reload
重启之后测试一下~是否成功设定完成! 输入指令~
curl -I imcat.tk
 
会输出:
HTTP/1.1 301 Moved Permanently
Server: nginx/0.7.65
Date: Tue, 03 Aug 2010 01:12:37 GMT
Content-Type: text/html
Content-Length: 185
Connection: keep-alive
Location: http://qinfy.net/
nginx rewrite 伪静态配置参数详细说明(转)
http://hi.baidu.com/hx10/blog/item/942a0ad784f3ffd0a144df94.html
nginx rewrite 伪静态配置参数和使用例子 附正则使用说明
正则表达式匹配,其中:
* ~ 为区分大小写匹配 
* ~* 为不区分大小写匹配 
* !~和!~*分别为区分大小写不匹配及不区分大小写不匹配
 
文件及目录匹配,其中:
* -f和!-f用来判断是否存在文件 
* -d和!-d用来判断是否存在目录 
* -e和!-e用来判断是否存在文件或目录 
* -x和!-x用来判断文件是否可执行
flag标记有:
* last 相当于Apache里的[L]标记,表示完成rewrite 
* break 终止匹配, 不再匹配后面的规则 
* redirect 返回302临时重定向 地址栏会显示跳转后的地址 
* permanent 返回301永久重定向 地址栏会显示跳转后的地址
一些可用的全局变量有,可以用做条件判断(待补全)
$args 
$content_length 
$content_type 
$document_root 
$document_uri 
$host 
$http_user_agent 
$http_cookie 
$limit_rate 
$request_body_file 
$request_method 
$remote_addr 
$remote_port 
$remote_user 
$request_filename 
$request_uri 
$query_string 
$scheme 
$server_protocol 
$server_addr 
$server_name 
$server_port 
$uri
结合QeePHP的例子
if (!-d $request_filename) { 
rewrite ^/([a-z-A-Z]+)/([a-z-A-Z]+)/?(.*)$ /index.php?namespace=user&controller=$1&action=$2&$3 last; 
rewrite ^/([a-z-A-Z]+)/?$ /index.php?namespace=user&controller=$1 last; 
break;
多目录转成参数
abc.domian.com/sort/2 => abc.domian.com/index.php?act=sort&name=abc&id=2
if ($host ~* (.*)\.domain\.com) { 
set $sub_name $1; 
rewrite ^/sort\/(\d+)\/?$ /index.php?act=sort&cid=$sub_name&id=$1 last; 
}
目录对换
/123456/xxxx -> /xxxx?id=123456
rewrite ^/(\d+)/(.+)/ /$2?id=$1 last;
例如下面设定nginx在用户使用ie的使用重定向到/nginx-ie目录下:
if ($http_user_agent ~ MSIE) { 
rewrite ^(.*)$ /nginx-ie/$1 break; 
}
目录自动加“/”
if (-d $request_filename){ 
rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent; 
}
禁止htaccess
location ~/\.ht { 
deny all; 
}
禁止多个目录
location ~ ^/(cron|templates)/ { 
deny all; 
break; 
}
禁止以/data开头的文件
可以禁止/data/下多级目录下.log.txt等请求;
location ~ ^/data { 
deny all; 
}
禁止单个目录
不能禁止.log.txt能请求
location /searchword/cron/ { 
deny all; 
}
禁止单个文件
location ~ /data/sql/data.sql { 
deny all; 
}
给favicon.ico和robots.txt设置过期时间;
这里为favicon.ico为99 天,robots.txt为7天并不记录404错误日志
location ~(favicon.ico) { 
log_not_found off; 
expires 99d; 
break; 
 
location ~(robots.txt) { 
log_not_found off; 
expires 7d; 
break; 
}
设定某个文件的过期时间;这里为600秒,并不记录访问日志
location ^~ /html/scripts/loadhead_1.js { 
access_log off; 
root /opt/lampp/htdocs/web; 
expires 600; 
break; 
}
文件反盗链并设置过期时间
这里的return 412 为自定义的http状态码,默认为403,方便找出正确的盗链的请求
“rewrite ^/ http://leech.c1gstudio.com/leech.gif;”显示一张防盗链图片
“access_log off;”不记录访问日志,减轻压力
“expires 3d”所有文件3天的浏览器缓存
location ~* ^.+\.(jpg|jpeg|gif|png|swf|rar|zip|css|js)$ { 
valid_referers none blocked *.c1gstudio.com *.c1gstudio.net localhost 208.97.167.194; 
if ($invalid_referer) { 
rewrite ^/ http://leech.c1gstudio.com/leech.gif; 
return 412; 
break; 
access_log off; 
root /opt/lampp/htdocs/web; 
expires 3d; 
break; 
}
只充许固定ip访问网站,并加上密码
root /opt/htdocs/www; 
allow 208.97.167.194; 
allow 222.33.1.2; 
allow 231.152.49.4; 
deny all; 
auth_basic "C1G_ADMIN"; 
auth_basic_user_file htpasswd;
将多级目录下的文件转成一个文件,增强seo效果
/job-123-456-789.html 指向/job/123/456/789.html
rewrite ^/job-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /job/$1/$2/jobshow_$3.html last;
将根目录下某个文件夹指向2级目录
如/shanghaijob/ 指向 /area/shanghai/
如果你将last改成permanent,那么浏览器地址栏显是 /location/shanghai/
rewrite ^/([0-9a-z]+)job/(.*)$ /area/$1/$2 last;
上面例子有个问题是访问/shanghai 时将不会匹配
rewrite ^/([0-9a-z]+)job$ /area/$1/ last; 
rewrite ^/([0-9a-z]+)job/(.*)$ /area/$1/$2 last;
这样/shanghai 也可以访问了,但页面中的相对链接无法使用,
如./list_1.html真实地址是/area /shanghia/list_1.html会变成/list_1.html,导至无法访问。
那我加上自动跳转也是不行咯
(-d $request_filename)它有个条件是必需为真实目录,而我的rewrite不是的,所以没有效果
if (-d $request_filename){ 
rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent; 
}
知道原因后就好办了,让我手动跳转吧
rewrite ^/([0-9a-z]+)job$ /$1job/ permanent; 
rewrite ^/([0-9a-z]+)job/(.*)$ /area/$1/$2 last;
文件和目录不存在的时候重定向:
if (!-e $request_filename) { 
proxy_pass http://127.0.0.1/; 
}
域名跳转
server 
listen 80; 
server_name jump.c1gstudio.com; 
index index.html index.htm index.php; 
root /opt/lampp/htdocs/www; 
rewrite ^/ http://www.c1gstudio.com/; 
access_log off; 
}
多域名转向
server_name http://www.c1gstudio.com/ http://www.c1gstudio.net/; 
index index.html index.htm index.php; 
root /opt/lampp/htdocs; 
if ($host ~ "c1gstudio\.net") { 
rewrite ^(.*) http://www.c1gstudio.com$1/ permanent; 
}
三级域名跳转
if ($http_host ~* "^(.*)\.i\.c1gstudio\.com$") { 
rewrite ^(.*) http://top.yingjiesheng.com$1/; 
break; 
}
域名镜向
server 
listen 80; 
server_name mirror.c1gstudio.com; 
index index.html index.htm index.php; 
root /opt/lampp/htdocs/www; 
rewrite ^/(.*) http://www.c1gstudio.com/$1 last; 
access_log off; 
}
某个子目录作镜向
location ^~ /zhaopinhui { 
rewrite ^.+ http://zph.c1gstudio.com/ last; 
break; 
}
discuz ucenter home (uchome) rewrite
rewrite ^/(space|network)-(.+)\.html$ /$1.php?rewrite=$2 last; 
rewrite ^/(space|network)\.html$ /$1.php last; 
rewrite ^/([0-9]+)$ /space.php?uid=$1 last;
discuz 7 rewrite
rewrite ^(.*)/archiver/((fid|tid)-[\w\-]+\.html)$ $1/archiver/index.php?$2 last; 
rewrite ^(.*)/forum-([0-9]+)-([0-9]+)\.html$ $1/forumdisplay.php?fid=$2&page=$3 last; 
rewrite ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/viewthread.php?tid=$2&extra=page\%3D$4&page=$3 last; 
rewrite ^(.*)/profile-(username|uid)-(.+)\.html$ $1/viewpro.php?$2=$3 last; 
rewrite ^(.*)/space-(username|uid)-(.+)\.html$ $1/space.php?$2=$3 last; 
rewrite ^(.*)/tag-(.+)\.html$ $1/tag.php?name=$2 last;
给discuz某版块单独配置域名
server_name bbs.c1gstudio.com news.c1gstudio.com; 
 
location = / { 
if ($http_host ~ news\.c1gstudio.com$) { 
rewrite ^.+ http://news.c1gstudio.com/forum-831-1.html last; 
break; 
}
discuz ucenter 头像 rewrite 优化
location ^~ /ucenter { 
location ~ .*\.php?$ 
#fastcgi_pass unix:/tmp/php-cgi.sock; 
fastcgi_pass 127.0.0.1:9000; 
fastcgi_index index.php; 
include fcgi.conf; 
 
location /ucenter/data/avatar { 
log_not_found off; 
access_log off; 
location ~ /(.*)_big\.jpg$ { 
error_page 404 /ucenter/images/noavatar_big.gif; 
location ~ /(.*)_middle\.jpg$ { 
error_page 404 /ucenter/images/noavatar_middle.gif; 
location ~ /(.*)_small\.jpg$ { 
error_page 404 /ucenter/images/noavatar_small.gif; 
expires 300; 
break; 
}
jspace rewrite
location ~ .*\.php?$ 
#fastcgi_pass unix:/tmp/php-cgi.sock; 
fastcgi_pass 127.0.0.1:9000; 
fastcgi_index index.php; 
include fcgi.conf; 
 
location ~* ^/index.php/ 
rewrite ^/index.php/(.*) /index.php?$1 break; 
fastcgi_pass 127.0.0.1:9000; 
fastcgi_index index.php; 
include fcgi.conf; 
}
Tags: ,
C#代码
  1. location ~ \.( html|js|css|png|gif|jpg|jpeg|bmp|swf)$ {     
  2.  
  3.     #如果后端的服务器返回502、504、执行超时等错误,自动将请求转发到 upstream负载均衡池中的另一台服务器,实现故障转移  
  4.     proxy_next_upstream http_502 http_504 error timeout invalid_header;  
  5.     proxy_cache cache_one;  
  6.  
  7.     #对不同的HTTP状态码设置不同的缓存时间  
  8.     proxy_cache_valid 200 10m;  
  9.     proxy_cache_valid 304 1m;  
  10.     proxy_cache_valid 301 302 1h;  
  11.     proxy_cache_valid any 1m;  
  12.  
  13.     #以域名、URI、参数组合成Web缓存的Key值,Nginx根据Key值哈希  
  14.     proxy_cache_key $host$uri$is_args$args;  
  15.     proxy_set_header Host $host;  
  16.     proxy_set_header X-Forwarded-For $remote_addr;  
  17.  
  18.     #如果没有缓存则通过proxy_pass转向tomcat请求  
  19.     proxy_pass http://tomcat_server_pool;  
  20.   
  21. }  
Tags: ,

Nginx upstream 相关配置

[不指定 2016/09/16 20:15 | by 刘新修 ]

Nginx_upstream实现:设置备份主机及过滤HTTP错误自动切除[8000=>Node服务器 || 2000=>默认错误处理页]:

C#代码
  1. #集群中的所有后台服务器的配置信息  
  2. upstream nodeJs {  
  3.     #server 123.56.233.208 weight=10;  
  4.     #server 127.0.0.1:3000 weight=10;  
  5.     server 127.0.0.1:8000;  
  6.     server 127.0.0.1:2000 backup;  
  7. }  
  8.  
  9. #调用所有的Server配置文件  
  10. include /usr/local/nginx/conf/vhosts/*.conf;  
  11.   
  12. server {  
  13.     listen 3000;  
  14.     server_name liuxinxiu.com;  
  15.   
  16.     add_header Proxy-By $upstream_http_server; #代理服务器Server  
  17.   
  18.     location / {  
  19.             proxy_pass http://nodeJs; #反向代理到后端Server  
  20.             proxy_set_header Host $host:3000;  
  21.             proxy_set_header X-Real-IP $remote_addr;  
  22.             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
  23.             #proxy_next_upstream error timeout invalid_header http_403 http_404;  
  24.     }  
  25. }  

Nginx=>2000端口默认错误处理页(相关配置):

C#代码
  1. server{  
  2.    listen 2000;  
  3.    server_name  127.0.0.1;  
  4.    index index.html index.htm index.php;  
  5.    root  /ftp/www/2000;  
  6.   
  7.    error_page  404  /index.html;  
  8.   
  9. }  

 

Tags: ,

NGINX 413 解决方法

[不指定 2015/10/14 17:14 | by 刘新修 ]
413 Request Entity Too Large
NGINX报出413错误是因请求body体上传文件过大导致,修改nginx.conf,在http{} 内部加入以下即可:
client_max_body_size 64M; #body体力最大上传大小,具体多少M根据实际情况填写

Nginx Post最大提交数据限制

[不指定 2015/05/13 20:39 | by 刘新修 ]

原以为是php本身的限制,查看配置文件无论是POST还是单个文件上传都满足要求:

#post最大提交量

post_max_size = 8M

#php给个文件最大限制

upload_max_filesize = 2M

************************************************************************

NGINX错误日志显示:

Nginx 【client intended to send too large body: 1065755 bytes】

http://at.liuxinxiu.com/2015/05/image/nginx_error_log.png

在Nginx.conf文件中添加:

client_max_body_size 64M; #多少M根据实际情况填写

重启即可!

resin服务管理

[不指定 2015/03/09 17:32 | by 刘新修 ]

重启服务  sh /usr/local/resin/bin/resin.sh -server youyuan restart

查看日志

C#代码
  1. root@pts/4 # tail -f /usr/local/resin/log/jvm-y  
  2. jvm-youyuan.log  jvm-yylc.log       
  3. 192.168.3.150 [/www/www.youyuan.com/web/WEB-INF/classes] 2015-03-09 17:27:20  
  4. root@pts/4 # tail -f /usr/local/resin/log/jvm-y  
  5. jvm-youyuan.log  jvm-yylc.log       
  6. 192.168.3.150 [/www/www.youyuan.com/web/WEB-INF/classes] 2015-03-09 17:27:20  
  7. root@pts/4 # tail -f /usr/local/resin/log/jvm-youyuan.log   
  8. Resin-4.0.35 (built Tue, 12 Feb 2013 10:05:50 PST)  
  9. Copyright(c) 1998-2012 Caucho Technology.  All rights reserved.  
  10.   
  11.   Using Resin(R) Open Source under the GNU Public License (GPL).  
  12.   
  13.   See http://www.caucho.com for information on Resin Professional,  
  14.   including caching, clustering, JNI acceleration, and OpenSSL integration.  
  15.   
  16. Starting Resin on Mon, 09 Mar 2015 17:27:23 +0800 (CST)  

 

mod_cband是一个限额用户带宽,最高下载速度,每秒访问请求速度和最高并发访问ip连接数的apache2模块。

1.安装mod_cband如下:

C#代码
  1. wget http://so.liuxinxiu.com/mod-cband-0.9.7.2.tgz  
  2. tar zxvf mod-cband-0.9.7.2.tgz  
  3. cd mod-cband-0.9.7.2  
  4. ./configure --with-apxs=/usr/local/apache/bin/apxs  
  5. make  
  6. make install  
##### whereis apxs可以看到你的apxs路径 #####
如果是yum 安装 httpd 找不到apxs需要单独再安装:# yum install httpd-devel //安装
查看路径:whereis apxs
 
[root@www sbin]# whereis apxs
apxs: /usr/sbin/apxs /usr/share/man/man8/apxs.8.gz
 
 
2.检查下你的apache配置文件httpd.conf是否加载了
 
执行以下:
C#代码
  1. grep cband /usr/local/apache2/conf/httpd.conf  
  2. 如果是云安装:
  3. grep cband /etc/httpd/conf/httpd.conf
 
查看模块有没加载到apache的路径上
LoadModulecband_module      modules/mod_cband.so
 
3.配置虚拟主机
 
C#代码
  1. #++++++++++默认入口+++++++++++++  
  2. #<VirtualHost *:80>  
  3. #    DocumentRoot /usr/local/apache/htdocs  
  4. #    ServerName 192.168.1.233  
  5. #</VirtualHost>  
  6.   
  7. <VirtualHost *:80>  
  8.    ServerName 192.168.1.233  
  9.    ServerAdmin admin@liuxinxiu.com  
  10.    DocumentRoot /usr/local/apache/htdocs  
  11.    CBandSpeed 1024 100 30  
  12.    CBandRemoteSpeed 50kb/s 5 3  
  13. </VirtualHost>  
说明:
 
CBandSpeed 1024 100 30 #CBandSpeed限定总的最大链接速度为1024kb,最多并发处理100个请求和30个链接
CBandRemoteSpeed 50kb/s 5 3 #CBandRemoteSpeed限定一个用户最多能有50kb的链接速度,最多并发5个请求和3个链接

 

开启Apache目录列表:

首先找到/usr/local/apache/conf/httpd.conf 文件搜索

#Include conf/extra/httpd-autoindex.conf (去掉注释# 启用)

修改/usr/local/apache/conf/extra/httpd-autoindex.conf

注释掉:#IndexOptions FancyIndexing HTMLTable VersionSort

启用:indexOptions FancyIndexing ScanHTMLTitles NameWidth=128 DescriptionWidth=256 HTMLTable VersionSort FoldersFirst

#######################################################################

之后遇到Apache列表索引中文乱码问,在httpd-autoindex.conf文件中添加:Charset=GBK

indexOptions Charset=GBK FancyIndexing ScanHTMLTitles NameWidth=128 DescriptionWidth=256 HTMLTable VersionSort FoldersFirst

重启Apache问题解决~

虚拟主机配置处添加:

C#代码
  1. <Directory "/data/web_bk">  
  2.    Options Indexes FollowSymLinks  
  3.    AllowOverride All  
  4.    Order allow,deny  
  5.    Order deny,allow  
  6.    Allow from all  
  7. </Directory>  

 Apache 配置显示版本信息:

C#代码
  1. ########### Add ##############  
  2. AddDefaultCharset GBK  
  3. ServerSignature On  
  4. ########### Add ##############  
  5.   
  6. Include shost/*.conf  

 

设置Discuz论坛伪静态

[不指定 2014/01/14 17:06 | by 刘新修 ]

把下面代码添加到:

<VirtualHost *:80>

    DocumentRoot /data/web_bk/bbs.XXXnet/htdocs

    ServerName bbs.XXX.net

<Directory "/data/web_bk/bbs.3snews.net/htdocs">

这里.....

</Directory>

</VirtualHost>

C#代码
  1. # 将 RewriteEngine 模式打开  
  2. RewriteEngine On  
  3.  
  4. # Rewrite 系统规则请勿修改  
  5. RewriteCond %{QUERY_STRING} ^(.*)$  
  6. RewriteRule ^topic-(.+)\.html$ portal.php?mod=topic&topic=$1&%1  
  7. RewriteCond %{QUERY_STRING} ^(.*)$  
  8. RewriteRule ^article-([0-9]+)-([0-9]+)\.html$ portal.php?mod=view&aid=$1&page=$2&%1  
  9. RewriteCond %{QUERY_STRING} ^(.*)$  
  10. RewriteRule ^forum-(\w+)-([0-9]+)\.html$ forum.php?mod=forumdisplay&fid=$1&page=$2&%1  
  11. RewriteCond %{QUERY_STRING} ^(.*)$  
  12. RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ forum.php?mod=viewthread&tid=$1&extra=page\%3D$3&page=$2&%1  
  13. RewriteCond %{QUERY_STRING} ^(.*)$  
  14. RewriteRule ^group-([0-9]+)-([0-9]+)\.html$ forum.php?mod=group&fid=$1&page=$2&%1  
  15. RewriteCond %{QUERY_STRING} ^(.*)$  
  16. RewriteRule ^space-(username|uid)-(.+)\.html$ home.php?mod=space&$1=$2&%1  
  17. RewriteCond %{QUERY_STRING} ^(.*)$  
  18. RewriteRule ^blog-([0-9]+)-([0-9]+)\.html$ home.php?mod=space&uid=$1&do=blog&id=$2&%1  
  19. RewriteCond %{QUERY_STRING} ^(.*)$  
  20. RewriteRule ^archiver/(fid|tid)-([0-9]+)\.html$ archiver/index.php?action=$1&value=$2&%1  

 

第一页 1 2 3 下页 最后页 [ 显示模式: 摘要 | 列表 ]