如何解决新安装的Magento 2.3.4后24小时清漆显示503错误
我遇到“错误503服务不可用”的问题,24小时后显示错误。我正在使用varnish-6.5.1使用最新的nginx服务器进行全页缓存。 Magento版本是2.3.4。我正在使用SSL证书,Magento处于开发人员模式。 我的清漆配置如下:
sudo systemctl edit --full varnish
[Unit]
Description=Varnish Cache,a high-performance HTTP accelerator
After=network-online.target nss-lookup.target
[Service]
Type=forking
KillMode=process
# Maximum number of open files (for ulimit -n)
LimitNOFILE=131072
# Locked shared memory - should suffice to lock the shared memory log
# (varnishd -l argument)
# Default log size is 80MB vsl + 1M vsm + header -> 82MB
# unit is bytes
LimitMEMLOCK=85983232
# Enable this to avoid "fork failed" on reload.
TasksMax=infinity
# Maximum size of the corefile.
LimitCORE=infinity
ExecStart=/usr/sbin/varnishd \
-a :6081 \
-a 127.0.0.1:8443,PROXY \
-p feature=+http2 \
-f /etc/varnish/default.vcl \
-s malloc,3G \
-p pipe_timeout=600 \
-p http_resp_hdr_len=65536 \
-p http_resp_size=98304
ExecReload=/usr/sbin/varnishreload
[Install]
WantedBy=multi-user.target
我的nginx配置如下:
upstream fastcgi_backend {
server unix:/run/php/php7.3-fpm.sock;
}
server {
listen 80;
listen [::]:80;
server_name 127.0.0.0.1 mysite.pl www.mysite.pl;
return 301 https://mysite.pl$request_uri;
}
server {
listen 443 ssl http2;
server_name 185.243.53.221 127.0.0.1 mysite.pl www.mysite.pl;
access_log /var/log/nginx/www.mysite.pl.log;
error_log /var/log/nginx/www.mysite.pl-error.log;
ssl_certificate_key /etc/nginx/ssl/www.mysite.pl.key;
ssl_certificate /etc/nginx/ssl/www.mysite.pl.pem;
ssl_protocols TLSv1.2;
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SH$
ssl_prefer_server_ciphers off;
add_header X-Frame-Options "SAMEORIGIN";
add_header Strict-Transport-Security max-age=31536000;
keepalive_timeout 600s;
location / {
proxy_pass http://127.0.0.1:6081;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Port 443;
proxy_set_header Host $host;
}
}
server {
listen 8080;
server_name 127.0.0.1 mysite.pl www.mysite.pl;
set $MAGE_ROOT /var/www/magento2;
include /var/www/magento2/nginx.conf.sample;
}
如何检查导致错误的原因?
解决方法
我使用命令
sudo varnishlog -d -q "vxid == 557088"
错误是“重启次数过多”,下面我粘贴了完整日志
* << Request >> 557088
- Begin req 557087 restart
- Timestamp Start: 1603710828.024454 0.000236 0.000000
- ReqStart 127.0.0.1 51688 a0
- ReqMethod GET
- ReqURL /
- ReqProtocol HTTP/1.0
- ReqHeader X-Real-IP: 83.6.151.188
- ReqHeader X-Forwarded-Proto: https
- ReqHeader X-Forwarded-Port: 443
- ReqHeader Host: wymienolej.pl
- ReqHeader X-Forwarded-Host: wymienolej.pl
- ReqHeader Connection: close
- ReqHeader cache-control: max-age=0
- ReqHeader upgrade-insecure-requests: 1
- ReqHeader user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/86.0.4240.75 Safari/537.36
- ReqHeader accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
- ReqHeader sec-fetch-site: none
- ReqHeader sec-fetch-mode: navigate
- ReqHeader sec-fetch-user: ?1
- ReqHeader sec-fetch-dest: document
- ReqHeader accept-language: pl-PL,pl;q=0.9,en-US;q=0.8,en;q=0.7
- ReqHeader cookie: AMCVS_8F99160E571FC0427F000101%40AdobeOrg=1; s_cc=true
- ReqHeader X-Forwarded-For: 83.6.151.188,127.0.0.1
- ReqHeader grace: none
- ReqHeader Accept-Encoding: gzip
- VCL_call RECV
- ReqUnset grace: none
- ReqHeader grace: none
- ReqURL /
- ReqUnset Accept-Encoding: gzip
- ReqHeader Accept-Encoding: gzip
- VCL_return hash
- VCL_call HASH
- VCL_return lookup
- Hit 557074 -3106.505552 259200.000000 0.000000
- VCL_call HIT
- VCL_return restart
- VCL_Error Too many restarts
- RespProtocol HTTP/1.1
- RespStatus 503
- RespReason Service Unavailable
- RespHeader Date: Mon,26 Oct 2020 11:13:48 GMT
- RespHeader Server: Varnish
- RespHeader X-Varnish: 557088
- VCL_call SYNTH
- RespHeader Content-Type: text/html; charset=utf-8
- RespHeader Retry-After: 5
- VCL_return deliver
- Timestamp Process: 1603710828.024479 0.000262 0.000025
- RespHeader Content-Length: 280
- Storage malloc Transient
- Filters
- RespHeader Connection: close
- Timestamp Resp: 1603710828.024534 0.000317 0.000055
- ReqAcct 763 0 763 205 280 485
- End
,
我将此代码添加到了我的default.vcl文件中:
import httpx
import asynctest
import pytest
class DebugClass:
async def post(self):
try:
async with httpx.AsyncClient() as client:
res = await client.post(url='http://localhost:8080',data=test_data)
return "OK"
except Exception as e:
return "NOK"
@pytest.mark.asyncio
async def test_debug_class_post():
with asynctest.patch('httpx.AsyncClient.post') as post_mock:
post_mock.side_effect = TimeoutError
debug_class = DebugClass()
res = await debug_class.post()
assert res == "NOK"
它似乎可以正常工作,目前没有503错误。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。