Get the most out of your Centmin Mod LEMP stack
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

    53,246
    12,117
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,655
    Local Time:
    8:32 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    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,439
    1,398
    113
    May 25, 2014
    Ratings:
    +2,187
    Local Time:
    6:32 PM
    Mainline
    10.2
    May I know what specific XF feature affected by this?
    Thanks!
     
  3. eva2000

    eva2000 Administrator Staff Member

    53,246
    12,117
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,655
    Local Time:
    8:32 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    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,439
    1,398
    113
    May 25, 2014
    Ratings:
    +2,187
    Local Time:
    6:32 PM
    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,990
    518
    113
    Apr 29, 2016
    Flanders
    Ratings:
    +1,647
    Local Time:
    12:32 PM
  6. eva2000

    eva2000 Administrator Staff Member

    53,246
    12,117
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,655
    Local Time:
    8:32 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    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