Learn about Centmin Mod LEMP Stack today
Become a Member

Xenforo Xenforo 2.x Updated Nginx vhost configuration June 2022

Discussion in 'Forum software usage' started by eva2000, Jun 15, 2022.

  1. eva2000

    eva2000 Administrator Staff Member

    49,766
    11,447
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,789
    Local Time:
    11:58 AM
    Nginx 1.21.x
    MariaDB 10.x
    On June 15, 2022 updated Xenforo 2.x Nginx configuration outlined here as it's been brought to my attention some Xenforo addons and Xenforo 2.x features may have issues with Centmin Mod's default /usr/local/nginx/conf/staticfiles.conf include file catching .js or .json extension routes meant for Xenforo 2.x. As such we can create a separate custom copy of /usr/local/nginx/conf/staticfiles.conf as /usr/local/nginx/conf/staticfiles_xf.conf and use that instead via these 4 steps.

    Step 1. copy /usr/local/nginx/conf/staticfiles.conf to /usr/local/nginx/conf/staticfiles_xf.conf
    Code (Text):
    cp -a /usr/local/nginx/conf/staticfiles.conf /usr/local/nginx/conf/staticfiles_xf.conf


    Step 2. edit /usr/local/nginx/conf/staticfiles_xf.conf and comment out the location context
    # for .js/.json location ~* \.(js|json)$ {}
    Code (Text):
      #  location ~* \.(js|json)$ {
      #add_header Pragma public;
      #add_header X-Frame-Options SAMEORIGIN;
      #add_header X-Xss-Protection "1; mode=block" always;
      #add_header X-Content-Type-Options "nosniff" always;
      #add_header Referrer-Policy "strict-origin-when-cross-origin";
      #add_header Access-Control-Allow-Origin *;
      #add_header Cache-Control "public, must-revalidate, proxy-revalidate, immutable, stale-while-revalidate=86400, stale-if-error=604800";
      #      access_log off;
      #      expires 30d;
      #      break;
      #      }


    Step 3. Then edit Nginx vhost switching to /usr/local/nginx/conf/staticfiles_xf.conf include file and commenting out /usr/local/nginx/conf/staticfiles.conf
    Code (Text):
      #include /usr/local/nginx/conf/staticfiles.conf;
      include /usr/local/nginx/conf/staticfiles_xf.conf;


    Step 4. Restart Nginx server
    Code (Text):
    ngxrestart


     
  2. rdan

    rdan Well-Known Member

    5,373
    1,349
    113
    May 25, 2014
    Ratings:
    +2,112
    Local Time:
    9:58 AM
    Mainline
    10.2
    May I know what specific XF feature affected by this?
    Thanks!
     
  3. eva2000

    eva2000 Administrator Staff Member

    49,766
    11,447
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,789
    Local Time:
    11:58 AM
    Nginx 1.21.x
    MariaDB 10.x
    Apparently, in XF 2 there's POST requests for .json like view.json and XF 2 addon https://xenforo.com/community/resources/digitalpoint-better-google-analytics.8752/'s host locally the JS code runs into this - I see in that thread you had previous reported 404 not found for that addon's .js extension requests that need to be handled by XF 2 and not Nginx. The above changes, allow XF 2 to handle them.
     
  4. rdan

    rdan Well-Known Member

    5,373
    1,349
    113
    May 25, 2014
    Ratings:
    +2,112
    Local Time:
    9:58 AM
    Mainline
    10.2
    What I did was just add it's own location, something like:
    Code:
    location /javascript/gtm.js {
    include php.conf
    }
     
  5. buik

    buik “The best traveler is one without a camera.”

    1,768
    480
    83
    Apr 29, 2016
    Flanders
    Ratings:
    +1,515
    Local Time:
    2:58 AM
  6. eva2000

    eva2000 Administrator Staff Member

    49,766
    11,447
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,789
    Local Time:
    11:58 AM
    Nginx 1.21.x
    MariaDB 10.x
    Yeah that takes care of .js files but not .json files.

    Thanks for the reminder! Need to update that too :)

    edit: the vhost.php generator has been updated too :D
     
    Last edited: Jun 16, 2022