Cloudflare on Multi Site Wordpress

What is the name of the domain?

example1.com example2.com

What is the error number?

301

What is the error message?

Infinite Redirection Loop

What is the issue you’re encountering

Infinite Redirection Loop

What steps have you taken to resolve the issue?

i dont know yet, im newbie

What are the steps to reproduce the issue?

Hi, i am currently managing 2 wordpress sites on my OpenBSD 7.5 server. Those two wordpress has two different domain example1 com and example2 com bought at namecheap but managed using different account, placed site at /var/www/example1/public/ and /var/www/example2/public/ and hosted on same server on my OpenBSD.
I tried to apply cloudflare on both sites using two cloudflare different account to avoid error but i got error 301. The error is when i try to access my example1 it automatically redirected to myexample2 and i dont wanted it to happened since it is completely different sites and different purposes. how to fix it?
here my nginx configuration for reference

user www;
worker_processes 1;

pid /var/run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
worker_connections 1024;
multi_accept on;
}

http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
default_type application/octet-stream;
keepalive_timeout 15;
client_body_timeout 30;
client_header_timeout 30;
send_timeout 30;
client_max_body_size 64m;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
access_log /var/www/logs/access.log;
error_log /var/www/logs/error.log;
gzip on;
gzip_disable “msie6”;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 5;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_types
application/atom+xml
application/javascript
application/json
application/ld+json
application/manifest+json
application/rss+xml
application/vnd.geo+json
application/vnd.ms-fontobject
application/x-font-ttf
application/x-web-app-manifest+json
application/xhtml+xml
application/xml
font/opentype
image/bmp
image/svg+xml
image/x-icon
text/cache-manifest
text/css
text/plain
text/vcard
text/vnd.rim.location.xloc
text/vtt
text/x-component
text/x-cross-domain-policy;

upstream php82 {
	server unix:run/php-fpm.sock;
}

include /etc/nginx/upstreams/*.conf;

map '' $upstream {
	default php83;
}

server_tokens off;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
client_body_buffer_size 10K;
client_header_buffer_size 1k;
large_client_header_buffers 2 1k;
#limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
#limit_req zone=one burst=5;

include /etc/nginx/conf.d/example1.conf;
include /etc/nginx/conf.d/example1.conf;

}

and here the server block for example1.conf

fastcgi_cache_path /var/www/example1 com/cache/ levels=1:2 keys_zone=example1 com:100m max_size=10g inactive=60m;

server {
listen 443;
listen [::]:443;
server_name example1 com;

ssl_certificate /etc/ssl/example1 com.fullchain.pem;
ssl_certificate_key /etc/ssl/private/example1 com.key;

ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers 'TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384';
ssl_ecdh_curve X25519:prime256v1:secp521r1:secp384r1;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_stapling on;
ssl_stapling_verify on;
resolver 1.1.1.1 1.0.0.1 valid=60s;

server_tokens off;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block";
#add_header X-Content-Type-Options "nosniff" always;
#add_header Content-Security-Policy "default-src 'self';" always;
add_header Referrer-Policy "same-origin";
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header Permissions-Policy "accelerometer=(), camera=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), payment=(), usb=()";

root /var/www/example1 com/public;
access_log /var/www/example1 com/logs/access.log;
error_log /var/www/example1 com/logs/error.log;

index index.php;

error_page 404 /404.html;
location = /404.html {
    root /var/www/example1 com/public;
    internal;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
    root /var/www/example1 com/public;
    internal;
}

location ~* /\.(?!well-known\/) {
    deny all;
}

location ~\.(ini|log|conf)$ {
    deny all;
}

location ~* /(?:uploads|files)/.*\.php$ {
    deny all;
}

location ~* \.(?:manifest|appcache|html?|xml|json)$ {
    expires 0;
}

location ~* \.(?:rss|atom)$ {
    expires 1h;
}

location ~* \.(?:webp|ico|cur|gz|svg|mp4|mp3|ogg|ogv|webm|htc)$ {
    expires 1y;
    access_log off;
}

location ~* \.svgz$ {
    expires 1y;
    access_log off;
    gzip off;
}

location ~* \.(?:css|js)$ {
    expires 1y;
    access_log off;
}

location ~* \.(?:ttf|ttc|otf|eot|woff|woff2)$ {
    expires 1y;
    access_log off;
    add_header Access-Control-Allow-Origin *;
}

location = /robots.txt {
    try_files $uri $uri/ /index.php?$args;
    access_log off;
    log_not_found off;
}

set $skip_cache 0;
if ($request_method = POST) {
    set $skip_cache 1;
}

if ($query_string != "") {
    set $skip_cache 1;
}

if ($request_uri ~* "/wp-admin/|/wp-json/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml|/cart/|/checkout/|/my-account/") {
    set $skip_cache 1;
}

if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in|edd_items_in_cart|woocommerce_items_in_cart") {
    set $skip_cache 1;
}

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

location = /xmlrpc.php {
    deny all;
    access_log off;
    log_not_found off;
}

location /.well-known/acme-challenge/ {
    rewrite ^/.well-known/acme-challenge/(.*) /$1 break;
    root /acme;
}

location = /.well-known/acme-challenge/ {
	return 404;
}

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:run/php-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;

    fastcgi_cache example1 com;
    fastcgi_cache_key "$scheme$request_method$host$request_uri";
    fastcgi_cache_valid 200 301 302 10m;
    fastcgi_cache_valid 404 1m;
    fastcgi_cache_use_stale error timeout updating http_500 http_503;
    fastcgi_cache_bypass $skip_cache;
    fastcgi_no_cache $skip_cache;
    fastcgi_cache_lock on;
    fastcgi_pass_header Set-Cookie;
    fastcgi_pass_header Cookie;
    fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
    fastcgi_cache_lock_timeout 5s;
    fastcgi_cache_methods GET HEAD;
    add_header X-Fastcgi-Cache $upstream_cache_status;
    add_header Cache-Control "public, max-age=600";
}

}

server {
listen 80;
listen [::]:80;
server_name example1 com;

return 301 https://example1 com$request_uri;

}

server {
listen 80;
listen [::]:80;
server_name www.example1 com;

return 301 https://example1 com$request_uri;

}

and here the example2.conf server block

fastcgi_cache_path /var/www/example2 com/cache/ levels=1:2 keys_zone=example2 com:100m max_size=10g inactive=60m;

server {
listen 443;
listen [::]:443;
server_name example2 com;

ssl_certificate /etc/ssl/example2 com.fullchain.pem;
ssl_certificate_key /etc/ssl/private/example2 com.key;

ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers 'TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384';
ssl_ecdh_curve X25519:prime256v1:secp521r1:secp384r1;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_stapling on;
ssl_stapling_verify on;
resolver 1.1.1.1 1.0.0.1 valid=60s;

server_tokens off;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block";
#add_header X-Content-Type-Options "nosniff" always;
#add_header Content-Security-Policy "default-src 'self';" always;
add_header Referrer-Policy "same-origin";
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header Permissions-Policy "accelerometer=(), camera=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), payment=(), usb=()";

root /var/www/example2 com/public;
access_log /var/www/example2 com/logs/access.log;
error_log /var/www/example2 com/logs/error.log;

index index.php;

error_page 404 /404.html;
location = /404.html {
    root /var/www/example2 com/public;
    internal;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
    root /var/www/example2 com/public;
    internal;
}

location ~* /\.(?!well-known\/) {
    deny all;
}

location ~\.(ini|log|conf)$ {
    deny all;
}

location ~* /(?:uploads|files)/.*\.php$ {
    deny all;
}

location ~* \.(?:manifest|appcache|html?|xml|json)$ {
    expires 0;
}

location ~* \.(?:rss|atom)$ {
    expires 1h;
}

location ~* \.(?:webp|ico|cur|gz|svg|mp4|mp3|ogg|ogv|webm|htc)$ {
    expires 1y;
    access_log off;
}

location ~* \.svgz$ {
    expires 1y;
    access_log off;
    gzip off;
}

location ~* \.(?:css|js)$ {
    expires 1y;
    access_log off;
}

location ~* \.(?:ttf|ttc|otf|eot|woff|woff2)$ {
    expires 1y;
    access_log off;
    add_header Access-Control-Allow-Origin *;
}

location = /robots.txt {
    try_files $uri $uri/ /index.php?$args;
    access_log off;
    log_not_found off;
}

set $skip_cache 0;
if ($request_method = POST) {
    set $skip_cache 1;
}

if ($query_string != "") {
    set $skip_cache 1;
}

if ($request_uri ~* "/wp-admin/|/wp-json/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml|/cart/|/checkout/|/my-account/") {
    set $skip_cache 1;
}

if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in|edd_items_in_cart|woocommerce_items_in_cart") {
    set $skip_cache 1;
}

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

location = /xmlrpc.php {
    deny all;
    access_log off;
    log_not_found off;
}

location /.well-known/acme-challenge/ {
    rewrite ^/.well-known/acme-challenge/(.*) /$1 break;
    root /acme;
}

location = /.well-known/acme-challenge/ {
	return 404;
}

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:run/php-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;

    fastcgi_cache example2 com;
    fastcgi_cache_key "$scheme$request_method$host$request_uri";
    fastcgi_cache_valid 200 301 302 10m;
    fastcgi_cache_valid 404 1m;
    fastcgi_cache_use_stale error timeout updating http_500 http_503;
    fastcgi_cache_bypass $skip_cache;
    fastcgi_no_cache $skip_cache;
    fastcgi_cache_lock on;
    fastcgi_pass_header Set-Cookie;
    fastcgi_pass_header Cookie;
    fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
    fastcgi_cache_lock_timeout 5s;
    fastcgi_cache_methods GET HEAD;
    add_header X-Fastcgi-Cache $upstream_cache_status;
    add_header Cache-Control "public, max-age=600";
}

}

server {
listen 80;
listen [::]:80;
server_name example2 com;

return 301 https://example2 com$request_uri;

}

server {
listen 80;
listen [::]:80;
server_name www.example2 com;

return 301 https://example2 com$request_uri;

}

You don’t mention the sites so people can’t look, but the most common reason for “too many redirects” is using Flexible SSL mode.

Check that your SSL/TLS setting is set to “Full (strict)” or “Strict” in your dashboard here…
https://dash.cloudflare.com/?to=/:account/:zone/ssl-tls

Otherwise it may be redirects on your origin, but without the site no-one can check that.

1 Like

im so sorry, i decided to remove the cloudflare since i have to keep the site running, if i keep cloudflare, it keep redirected on infinite loop. i did try from flexible till full strict, does not works

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.