最近,我将服务器从Apache更改为Nginx。这是因为该网站正在使用file_get_contents的另一个网站。当外部网站关闭或运行缓慢时,线程就会被关闭,服务器也会崩溃。就像多米诺骨牌效应。
然后,我将服务器从Apache2升级到Nginx,并使用了一个也运行Nginx的反向代理。这样,我可以在一个IP地址上运行多个具有多个域的服务器。
今天,我注意到来访者在拼命地往下走,动作很快。服务器非常慢,甚至会暂停几次。
I有3台服务器:
当连接到第一个网站时,速度非常慢(等待时间约为28秒),但连接到第二个网站时,速度非常快(大约0.8秒)。
我当时对Nginx知之甚少,因为我已经使用Apache2 2年了。
Reverse代理-/etc/nginx/sites可用/默认
是的,我在第一个领域有很多域
server {
listen 80;
server_name domain.com www.domain.com domain.org www.domain.org domain.co.uk www.domain.co.uk domain.co www.domain.co domain.me www.domain.me domain.se www.domain.se;
location / {
proxy_pass http://192.168.1.237;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
real_ip_header X-Real-IP;
real_ip_recursive on;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
listen 80;
server_name www.domain2.com domain2.com;
location / {
proxy_pass http://192.168.1.230;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
server {
listen 80;
server_name controller.domain.com;
location / {
allow 84.71.x.x/21;
allow 192.168.0.0/16;
deny all;
proxy_pass http://192.168.1.1;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}1st etc服务器- /etc/nginx/nginx.conf
user www-data;
worker_processes 10;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 1024;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##
#include /etc/nginx/naxsi_core.rules;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}1st etc服务器-/etc/nginx/sites可用/默认
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html/pi;
index index.php;
# It seems like the server only needed 1 of these, as all the other domains redirects to the main domain
server_name domain.com domain.org;
error_page 404 /missing.php;
error_page 403 /forbidden.php;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param REMOTE_ADDR $http_x_real_ip;
# With php5-cgi alone:
#fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}我不知道问题出在哪里,所以我链接了一些配置文件。
我使用了一些这篇文章 (我没有更改端口,只是停止了apache,安装了Nginx,然后卸载了apache)来从Apache迁移到nginx。
所有的电脑都在运行Debian。
目前每小时大约有4600个请求,我用以下命令计算:sudo grep -o '13/Feb/2018:09:' /var/log/nginx/access.log | wc -l
你有什么建议或事情我可以尝试解决吗?
这个问题似乎发生在高负荷下。
服务器现在似乎工作正常。我找到了此链接,并以这个配置为例。然后删除/编辑以匹配基础结构(反向代理、自定义参数)。
下面是最后一周/一天的服务器状态的可视化表示(Monitorix)。我在图片上添加了一个描述。
我将让服务器继续运行,因为目前的配置,并看看我是否遇到任何未来的错误。
差不多一个星期了,我希望问题已经解决了.问题又回来了。
现在它不断地抛出这个错误:
2018/02/17 18:52:21 [error] 18185#18185: *2065 connect() to unix:/var/run/php5-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 66.249.x.x, server: domain.org, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "domain.org"我还发现,服务器通过重新启动php5-fpm获得了非常快的速度,但只有大约10秒。
我认为这是奇怪的,服务器已经运行了一个星期,现在突然这个问题再次发生?
RAM的容量为1GB/4GB,当查看监控时(除了所有网络活动下降的情况外)唯一明显的不同是这。最后的冲击,是网站崩溃的时候,但我认为这并不重要。
有什么建议吗?
在过去的一周里,我一直密切关注着这台服务器,而且它一直令人难以置信的不稳定。有时我非常快,其他时候它可以在网页中加载大约20秒。
我改变了nginx.conf的配置,但似乎只帮了一点点忙。我开始认为PHP是问题所在,而不是nginx。我找到了这个问题,它链接到一篇文章。我把www.conf里的几个下午改成了:
pm.max_children = 20
pm.start_servers = 8
pm.min_spare_servers = 8
pm.max_spare_servers = 15
pm.max_requests = 500在过去一小时内,响应时间约为400毫秒。
我要等一会儿,看看问题是否再次发生。
发布于 2018-06-21 22:02:41
差不多半年后,这个问题又发生了。可能是因为游客几乎翻了一番,所以它需要更多的资源。
我下载了一个名为网数据的新监控工具,并在php5-fpm和找到这个重新启动后进行了仔细检查。
当PHP套接字最大限度地发挥作用时,网站就慢了下来。所以我发现了问题。
在增加PHP资源之后,它再次运行良好
这些是我当前的/etc/php5/fpm/pool.d/www.conf设置
pm = dynamic
pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers = 20
pm.max_requests = 2000是的,这不是PHP重载的解决方案,而是为它提供更多的资源。
发布于 2018-02-13 11:26:55
首先,我会试图找出链的哪一部分使网站慢下来。
ab工具。例如,为了发送3000个请求和100个并发请求,使用: ab -c 100 -n 3000 http://domain.de/,我还使用它来检查我的PHP池套接字文件设置在负载下是否正常工作。https://serverfault.com/questions/897002
复制相似问题