Help Setting up xenforo with LXD/C containers using nginx proxy

Skyrider

Active member
I hope someone here has experience setting up xenforo with lxd containers. Here's what I have on the web container :

server {
server_name xxxxxx;
access_log /var/www/logs/access.log;
error_log /var/www/logs/error.log;
root /var/www/xxxxx.com;
index index.php index.html index.htm;

location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
#fastcgi_param HTTP_SCHEME https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}

And the nginx reverse proxy server block on the proxy containing the xenforo files and database:

server {
listen 80 proxy_protocol;
listen [::]:80 proxy_protocol;

server_name xxxxxxx;

location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://ipofthewebcontainer;
}

real_ip_header proxy_protocol;
set_real_ip_from 127.0.0.1;

listen [::]:443 proxy_protocol ssl ipv6only=on; # managed by Certbot
listen 443 proxy_protocol ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/xxxxxxx/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/xxxxxxx/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header Referrer-Policy "origin";

ssl_stapling on;
ssl_stapling_verify on;
}

Now, I've attempted to include:

location / {
index index.php index.html index.htm;

try_files $uri $uri/ /index.php?$uri&$args;
deny 159.138.0.0/16;
}

location = /showthread.php {
return 301 /threads/$arg_t/;
}

location = /member.php {
return 301 /members/$arg_u/;
}

location /install/data/ {
internal;
}

location /install/templates/ {
internal;
}

location /internal_data/ {
internal;
}

location /library/ {
internal;
}

location /src/ {
internal;
}

error_page 404 /index.php;

on many locations (both nginx proxy nginx and web nginx), but for some reason I keep getting ERR_TOO_MANY_REDIRECTS

Oddly enough the admin panel of xenforo seems to be working. Even if I disable friendly URL in the admin panel, the redirect issue persists... Can someone help me with this and if possible, share their nginx proxy/web nginx block codes? I've been trying to get this sorted for over 24 hours, and I really am not getting any further.
 
Last edited:

Skyrider

Active member
Apparently, ERR_TOO_MANY_REDIRECTS is not caused by the proxy nor web nginx files.

On a new installation (fresh), Xenforo works perfectly.. No issues. But whenever I restore my web files and SQL file backups, I keep getting ERR_TOO_MANY_REDIRECTS for unknown reasons. Like above, admin panel works fine. Just not the main forums.
 

Skyrider

Active member
Thanks for the reply, but I figured it out.

The many redirects was caused by the forums set to https://, with the redirection in place, it was causing it to loop.
 

Skyrider

Active member
Domain nginx:

server {
#listen 80;
server_name domain;

#listen 443 ssl http2;
#listen [::]:443 ipv6only=on ssl http2;
root /var/www/location;
client_max_body_size 64M;

## CACHING ##

location ~* \.(css|js|ico|gif|jpeg|jpg|webp|png|svg|eot|otf|woff|woff2|ttf|ogg)$ {
expires 30d;
add_header Cache-Control "public, no-transform";
}

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/x-javascript text/xml application/xml application/xml+rss text/javascript;


## XENFORO 2 CODE ##

location / {
index index.php index.html index.htm;

try_files $uri $uri/ /index.php?$uri&$args;
deny 159.138.0.0/16;
}

location = /showthread.php {
return 301 /threads/$arg_t/;
}

location = /member.php {
return 301 /members/$arg_u/;
}

location /install/data/ {
internal;
}

location /install/templates/ {
internal;
}

location /internal_data/ {
internal;
}

location /library/ {
internal;
}

location /src/ {
internal;
}

error_page 404 /index.php;

if ($http_user_agent ~ (HUAWEIFRD|OPPO|FRD-AL00|BLEXBot|AhrefsBot) ) {
return 403;
}


## END XENFORO 2 CODE ##

location ~ \.php$ {

fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param HTTP_SCHEME https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
try_files $uri $uri/ =404;
fastcgi_intercept_errors on;
client_max_body_size 32M;
fastcgi_read_timeout 150;
}
}

Nginx proxy:

server {
#listen 80 proxy_protocol;
#listen [::]:80 proxy_protocol;

server_name domain;

location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://10.75.254.16;
}

real_ip_header proxy_protocol;
set_real_ip_from 127.0.0.1;

listen [::]:443 proxy_protocol ssl ipv6only=on; # managed by Certbot
listen 443 proxy_protocol ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/domain/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/domain/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header Referrer-Policy "origin";

ssl_stapling on;
ssl_stapling_verify on;
}

server {
if ($host = domain) {
return 301 https://$host$request_uri;
} # managed by Certbot

listen 80 proxy_protocol;
listen [::]:80 proxy_protocol;

server_name domain;
return 404; # managed by Certbot
}
 
Top