【求助】nginx在访问量稍大的情况下,出现503 Service Temporarily Unavailable错误

明日的明日 明日的明日 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
当前环境是LNMP,使用jmeter测试时,300的并发,循环5次,当中有20%的请求会出现503错误,看了网上的资料是说,做了ip访问次数限制(limit_conn),但是我再配置文件中没有设置,比较头大,请各位帮下忙,十分感谢
下面是nginx的配置文件:
/etc/nginx/nginx.conf:

# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
worker_rlimit_nofile 65535;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
worker_connections 20480;
use epoll;
}

http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 200;
types_hash_max_size 2048;

fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;

include /etc/nginx/mime.types;
default_type application/octet-stream;

# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;

server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;

# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;

location / {
}

error_page 404 /404.html;
location = /40x.html {
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}

# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }

}


/etc/nginx/conf.d/default.conf:

server {
listen 80;
server_name 127.0.0.1;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
# \.php 只处理动态请求,对于静态资源请求由下面的 location匹配和处理
location ~ \.php {
root /www/html;
fastcgi_pass 127.0.0.1:9000;
#包含nginx服务器传递给fastcgi程序的参数,php中通过$_SERVER['参数名']可获取
include fastcgi.conf;
#定义变量$fastcgi_script_name_new赋值为$fastcgi_script_name变量
set $path_info "";
set $fastcgi_script_name_new $fastcgi_script_name;
#判断url是否是pathinfo形式的,如果是则把这个url分割成两部分,index.php入口文件之后的pathinfo部分存入$path_info变量中,剩下的部分和$document_root根目录定位index.php入口文件在文件系统中的绝对路径 .

if ($fastcgi_script_name ~* "^(.+\.php)(/.+)$" ) {
set $fastcgi_script_name_new $1;
set $path_info $2;
}

#对fastcgi.conf中的SCRIPT_FILENAME和SCRIPT_NAME fastcgi参数进行重写,目的是指定入口文件在文件系统中的绝对路径给script_filename参数,让fastcgi知道index.php文件位置。
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name_new;
fastcgi_param SCRIPT_NAME $fastcgi_script_name_new;
#定义一个新的nginx服务器传递给fastcgi的参数PATH_INFO,thinkphp需要这个入口文件index.php后的pathinfo信息
fastcgi_param PATH_INFO $path_info;
}
# 用来匹配静态资源,如果不是静态资源就重写,然后重新轮训所有的location块,由上面的location块匹配后动态处理这个请求
location / {
root /www/html;
index index.php index.html index.htm;

if (!-e $request_filename){
rewrite ^(.*)$ /index.php$1 last;
}
}
}

...全文

相关推荐

解决nginx 503 Service Temporarily Unavailable方法示例

主要介绍了解决nginx 503 Service Temporarily Unavailable方法示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

weixin_38746701

nginx connect() to unix:/var/run/php-fpm.sock failed (11: Resource temporarily unavailable)

主要介绍了nginx connect() to unix:/var/run/php-fpm.sock failed (11: Resource temporarily unavailable),需要的朋友可以参考下

weixin_38628612

解决Nginx 503错误[项目源码]

文章详细介绍了如何解决Nginx服务器出现的503 Service Temporarily Unavailable错误。作者通过分析发现,错误源于nginx.conf中单IP访问次数限制设置过低,导致页面刷新时因加载过多资源(如JS、CSS、图片)而触发限制。通过调整limit_req_zone和limit_req参数(如增大rate和burst值),问题得到解决。文中还提供了完整的nginx.conf配置示例,包括代理设置、缓存配置和访问限制等,为遇到类似问题的开发者提供了实用参考。

gamma

详解nginx的请求限制(连接限制和请求限制)

主要介绍了详解nginx的请求限制(连接限制和请求限制),小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

weixin_38605188

Nginx limit 限制访问模块的方法

本篇文章主要介绍了Nginx limit 限制访问模块的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

weixin_38518376
评论 1
收藏 已收藏
分享
返回顶部