среда, 29 апреля 2020 г.

Magento 500 error Premature end of script headers: index.php, Error parsing script headers, (22)Invalid argument

[Wed Apr 29 13:55:43.181652 2020] [proxy_fcgi:error] [pid 113977] [client 127.0.0.1:38830] Premature end of script headers: index.php, referer: https://domain.tld/us/catalogsearch/result/?q=jacket

[Wed Apr 29 13:55:43.181721 2020] [proxy_fcgi:error] [pid 113977] [client 127.0.0.1:38830] AH01070: Error parsing script headers, referer: https://domain.tld/us/catalogsearch/result/?q=jacket

[Wed Apr 29 13:55:43.181726 2020] [proxy_fcgi:error] [pid 113977] (22)Invalid argument: [client 127.0.0.1:38830] AH01075: Error dispatching request to : , referer: https://domain.tld/us/catalogsearch/result/?q=jacket

Issue https://github.com/magento/magento2/issues/7657
https://cloud.githubusercontent.com/assets/3441674/20826784/5002f712-b8a8-11e6-95cf-ab8d9d94e239.png

header X-Magento-Tags size more than header size limit

среда, 22 апреля 2020 г.

Magento rewrite 404 error with checkout

It was dev site with enabled basic auth
Access log displayed 404 error
There was an error in nginx error log
 is not found (2: No such file or directory)

Working Apache config was
<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    RewriteCond %{REQUEST_METHOD} ^TRAC[EK]
    RewriteRule .* - [L,R=405]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule .* index.php [L]
</IfModule>

I was moving to Nginx and got an error 404, because I only disabled auth with
location /onestepcheckout/ {
    auth_basic off; 
}
I had to add auth off for checkout, but I forgot about rewrite
try_files $uri/ $uri/ /index.php$is_args$args;
It was a reason.
Resolving error was

location / {     
    try_files $uri/ $uri/ /index.php$is_args$args;
}

location /onestepcheckout/ {
    auth_basic off;
    try_files $uri $uri/ /index.php$is_args$args;
}

# POST response
location /rest/ {
    auth_basic off;
    try_files $uri $uri/ /index.php$is_args$args;
}

пятница, 17 апреля 2020 г.

Magento CORS error (Access-Control-Allow-Origin)

https://absolutecommerce.co.uk/blog/cors-in-magento-2

/etc/nginx/magento2-cors.conf
add_header 'Access-Control-Allow-Origin' '*' 'always'; 
if ($request_method = 'OPTIONS') { 
  add_header 'Access-Control-Allow-Origin' '*' 'always'; 
  add_header 'Access-Control-Allow-Headers' 'x-requested-with' 'always'; 
  add_header 'Access-Control-Max-Age' 86400 'always'; 
  add_header 'Content-Length' 0 'always'; return 204; 
}

location /static/ { 
  location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ { 
    add_header X-Frame-Options "SAMEORIGIN"; 
    include /etc/nginx/magento2-cors.conf; 
  } 
  location ~* \.(zip|gz|gzip|bz2|csv|xml)$ { 
    add_header X-Frame-Options "SAMEORIGIN"; 
    include /etc/nginx/magento2-cors.conf; 
  } 
  add_header X-Frame-Options "SAMEORIGIN"; 
  include /etc/nginx/magento2-cors.conf; 
}

explanation CORS:

Header Access-Control-Allow-* - это заголовки ответа, их должен отправлять сервер в ответ на запрос. 
Если запрос OPTIONS (браузер шлет сам перед основным запросом для проверки прав), то сервер должен так же ответить этими заголовками, но со статусом 204 и без тела
с клиента должен быть только заголовок Origin (откуда пришел запрос), если клиент в браузере, то браузер сам его отправит (X-Requested-With кстати тоже сам отправит)
а эти:
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods" : "GET,POST,PUT,DELETE,OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"
должны быть с сервера, притом из Access-Control-Allow-Headers можно смело убрать Access-Control-Allow-Headers и X-Requested-With (первый Вы и не должны отправлять, а второй разрешен по умолчанию)

четверг, 9 апреля 2020 г.

Magento 2 Some links from staging home page redirect to the production site

Some links from staging home page redirect to the production site.
Analyzing...
It is home page, so, I have to check cms* tables.
I checked with

select title,content from cms_block where content like '%www.prod.com%';

and found three records
I modified them with  variable {{config path="web/secure/base_url"}} instead of prod domain.
It could be done via Admin Panel or via

Cleared FPC cache
UPDATE cms_block set content = REPLACE(content, 'https://www.prod.com/', '{{config path="web/secure/base_url"}}') WHERE content LIKE '%https://www.prod.com/%';