當前環境是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;
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/72356.html
標籤:應用服務器
