phpwordpressnginxsslvps

Error with Nginx (ERR_TOO_MANY_REDIRECTS) in VPS Hostinger default config WordPress


I'm having a problem with my Wordpress hosting on a Hostinger VPS with CloudPanel and NGINX. I've tried reinstalling it, it worked for 10 minutes (which is strange) and then it stopped working.

Basically, I try to access the site and I get the following response: "ERR_TOO_MANY_REDIRECTS" However, when I access wp-login, I can fill in the username and password, but it just reloads the page.

NGINX Error Log - Nothing PHP-FPM Error Log - Nothing WP_LOG - Nothing

This is the default configuration file:

server {
  listen 80;
  listen [::]:80;
  listen 443 quic;
  listen 443 ssl;
  listen [::]:443 quic;
  listen [::]:443 ssl;
  http2 on;
  http3 off;
  ssl_certificate_key /etc/nginx/ssl-certificates/www.casamarx.com.br.key;
  ssl_certificate /etc/nginx/ssl-certificates/www.casamarx.com.br.crt;
  server_name casamarx.com.br;
  return 301 https://www.casamarx.com.br$request_uri;
}

server {
  listen 80;
  listen [::]:80;
  listen 443 quic;
  listen 443 ssl;
  listen [::]:443 quic;
  listen [::]:443 ssl;
  http2 on;
  http3 off;
  ssl_certificate_key /etc/nginx/ssl-certificates/www.casamarx.com.br.key;
  ssl_certificate /etc/nginx/ssl-certificates/www.casamarx.com.br.crt;
  server_name www.casamarx.com.br www1.casamarx.com.br;
  root /home/casamarx/htdocs/www.casamarx.com.br;

  access_log /home/casamarx/logs/nginx/access.log main;
  error_log /home/casamarx/logs/nginx/error.log;

  if ($scheme != "https") {
    rewrite ^ https://$host$request_uri permanent;
  }

  location ~ /.well-known {
    auth_basic off;
    allow all;
  }

  location ~/\.git {
    deny all;
  }

  location = /xmlrpc.php {
    deny all;
  }

  location ~/(wp-admin/|wp-login.php) {
    #auth_basic "Restricted Area";
    #auth_basic_user_file /home/site-user/.htpasswd;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header Host $host;
    proxy_pass http://127.0.0.1:8080;
    proxy_max_temp_file_size 0;
    proxy_connect_timeout      7200;
    proxy_send_timeout         7200;
    proxy_read_timeout         7200;
    proxy_buffer_size          128k;
    proxy_buffers              4 256k;
    proxy_busy_buffers_size    256k;
    proxy_temp_file_write_size 256k;
  }

  location / {
    proxy_pass http://127.0.0.1:8080;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_hide_header X-Varnish;
    proxy_redirect off;
    proxy_max_temp_file_size 0;
    proxy_connect_timeout      720;
    proxy_send_timeout         720;
    proxy_read_timeout         720;
    proxy_buffer_size          128k;
    proxy_buffers              4 256k;
    proxy_busy_buffers_size    256k;
    proxy_temp_file_write_size 256k;
  }

  location ~* ^.+\.(css|js|jpg|jpeg|gif|png|ico|gz|svg|svgz|ttf|otf|woff|woff2|eot|mp4|ogg|ogv|webm|webp|zip|swf|map)$ {
    # WordPress Multisite Subdirectory
    rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 break;
    rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 break;
    add_header Access-Control-Allow-Origin "*";
    add_header alt-svc 'h3=":443"; ma=86400';
    expires max;
    access_log off;
  }

  if (-f $request_filename) {
    break;
  }
}

server {
  listen 8080;
  listen [::]:8080;
  server_name www.casamarx.com.br www1.casamarx.com.br;
  root /home/casamarx/htdocs/www.casamarx.com.br;

  include /etc/nginx/global_settings;

  try_files $uri $uri/ /index.php?$args;
  index index.php index.html;

  location ~ \.php$ {
    include fastcgi_params;
    fastcgi_intercept_errors on;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    try_files $uri =404;
    fastcgi_read_timeout 3600;
    fastcgi_send_timeout 3600;
    fastcgi_param HTTPS "on";
    fastcgi_param SERVER_PORT 443;
    fastcgi_pass 127.0.0.1:15001;
    fastcgi_param PHP_VALUE "
    error_log=/home/casamarx/logs/php/error.log;
    memory_limit=512M;
    max_execution_time=60;
    max_input_time=60;
    max_input_vars=10000;
    post_max_size=64M;
    upload_max_filesize=64M;
    date.timezone=UTC;
    display_errors=off;";
  }

  # WordPress Multisite Subdirectory
  if (!-e $request_filename) {
    rewrite /wp-admin$ https://$host$uri permanent;
    rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
    rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
  }

  if (-f $request_filename) {
    break;
  }
}

Portuguese:

Estou passando por um problema com minha hospedagem Wordpress em uma VPS do Hostinger com CloudPanel e NGINX. Já tentei reinstalar, funcionou por um tempo de 10 minutos (o que é estranho) e logo em seguida passou a não funcionar.

Basicamente tento entrar no site e meu retorno é: "ERR_TOO_MANY_REDIRECTS" Porém, quando entro no wp-login, consigo preencher usuário e senha, mas ele somente recarrega a página.

NGINX Error Log - Não tem nada PHP-FPM Error Log - Não tem nada WP_LOG - Não tem nada

I tried to modify the permissions, I tried to disable plugins (at the first occurrence), but nothing. I don't understand too much about nginx. But, I know when the VPS had the srv....hostinger.cloud (original domain) from Hostinger, don't currency anything like this error.


Solution

  • Using curl -I -L https://www.casamarx.com.br shows the redirect is done by WP to the non-www variant. Then you nginx config redirects back to the www-variant.

    Either change nginx to redirect to non-www, or set WP_HOME and WP_SITEURL to your site with www, e.g. using wp-config.php:

    define('WP_HOME', 'https://www.casamarx.com.br');
    define('WP_SITEURL', 'https://www.casamarx.com.br');
    

    When this works, you can change the URLs accordingly in WP General Settings and remove the 2 definitions from wp-config.

    See: https://www.wpbeginner.com/wp-tutorials/how-to-change-your-wordpress-site-urls-step-by-step/