NGINX Friendly URLs

Cupara

Well-known member
I know this has been discussed, I have seen the threads, tried suggestions, even tried to alter from XenForo 1.5 suggestions to work with 2.0.0 but I know PHP, not rewrite rules. LOL

So here is my problem, I run nginx, I used the information here, https://xenforo.com/help/friendly-urls/, but still does not work. I have added the information to the additional directives box for nginx on my Plesk Onyx install. I had it working at one point but javascript and other parts would not load so I scrapped it and started over. Now I'm here asking for guidance.

My XenForo is installed in the root directory, but I have it set to access forums using /forums/ so that I can set my portal on the main page.

Here is my nginx.conf under my domain vhosts folder.
Code:
#ATTENTION!
#
#DO NOT MODIFY THIS FILE BECAUSE IT WAS GENERATED AUTOMATICALLY,
#SO ALL YOUR CHANGES WILL BE LOST THE NEXT TIME THE FILE IS GENERATED.

server {
        listen 45.55.55.238:443 ssl http2;

        server_name goblintimes.com;
        server_name www.goblintimes.com;
        server_name ipv4.goblintimes.com;

        ssl_certificate             /usr/local/psa/var/certificates/ce$
        ssl_certificate_key         /usr/local/psa/var/certificates/ce$
        ssl_client_certificate      /usr/local/psa/var/certificates/ce$

        client_max_body_size 128m;

        root "/var/www/vhosts/goblintimes.com/httpdocs";
        access_log "/var/www/vhosts/system/goblintimes.com/logs/proxy_$
        error_log "/var/www/vhosts/system/goblintimes.com/logs/proxy_e$

        if ($host ~* ^www\.goblintimes\.com$) {
                rewrite ^(.*)$ https://goblintimes.com$1 permanent;
        }

location / {
                proxy_pass https://IP:7081;
                proxy_set_header Host             $host;
                proxy_set_header X-Real-IP        $remote_addr;
                proxy_set_header X-Forwarded-For  $proxy_add_x_forward$
                proxy_set_header X-Accel-Internal /internal-nginx-stat$
                access_log off;
        }

location /internal-nginx-static-location/ {
                alias /var/www/vhosts/goblintimes.com/httpdocs/;
                internal;
        }

location ~ ^/(plesk-stat|awstats-icon|webstat|webstat-ssl|ftps$
                proxy_pass https://IP:7081;
                proxy_set_header Host             $host;
                proxy_set_header X-Real-IP        $remote_addr;
                proxy_set_header X-Forwarded-For  $proxy_add_x_forward$
                proxy_set_header X-Accel-Internal /internal-nginx-stat$
                access_log off;
        }

location ~ ^/~(.+?)(/.*?\.php)(/.*)?$ {
                alias /var/www/vhosts/goblintimes.com/web_users/$1/$2;
                fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
                fastcgi_param PATH_INFO $fastcgi_path_info;
                fastcgi_pass "unix:///var/www/vhosts/system/goblintime$
                include /etc/nginx/fastcgi.conf;
        }

location ~ ^/~(.+?)(/.*)?$ {
                proxy_pass https://IP:7081;
                proxy_set_header Host             $host;
                proxy_set_header X-Real-IP        $remote_addr;
                proxy_set_header X-Forwarded-For  $proxy_add_x_forward$
                proxy_set_header X-Accel-Internal /internal-nginx-stat$
                access_log off;
        }

        location ~ \.php(/.*)?$ {
                fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
                fastcgi_param PATH_INFO $fastcgi_path_info;
                fastcgi_pass "unix:///var/www/vhosts/system/goblintime$
                include /etc/nginx/fastcgi.conf;
        }

        location ~ /$ {
                index "index.html" "index.cgi" "index.pl" "index.php" $
        }

        add_header X-Powered-By PleskLin;

        include "/var/www/vhosts/system/goblintimes.com/conf/vhost_ngi$
}

server {
        listen IP:80;

        server_name goblintimes.com;
        server_name www.goblintimes.com;
        server_name ipv4.goblintimes.com;

        client_max_body_size 128m;

        return 301 https://$host$request_uri;
}

This is my additional directives:
Code:
location /forums/ {
    try_files $uri $uri/ /forums/index.php?$uri&$args;
    index index.php index.html;
}

location /forums/install/data/ {
    internal;
}
location /forums/install/templates/ {
    internal;
}
location /forums/internal_data/ {
    internal;
}
location /forums/library/ {
    internal;
}

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_pass    127.0.0.1:9000;
    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include         fastcgi_params;
}

All I get now is 404 error pages. I have manually changed the nginx.conf file for my domain to include those parameters under 'location /' but still no change.

I have also attached a screenshot of my nginx settings via plesk.

Give me Apache and I can do this all day but nginx is default for Plesk from Digital Ocean and I would rather stick with nginx instead of redoing the server and having more of a headache.

Thanks
 

Attachments

  • Apache   nginx Settings for goblintimes.com   Plesk Onyx 17.5.3.webp
    Apache nginx Settings for goblintimes.com Plesk Onyx 17.5.3.webp
    63.4 KB · Views: 52
Last edited:
You do not need to run any commands, except restart nginx after change: service nginx restart

So,

Nginx Rewrites For Xenforo Friendly Urls:


If Xenforo forum is installed in public web root i.e. /home/nginx/domains/newdomain.com/public, then you'll need to add and edit the following Nginx rewrites in /usr/local/nginx/conf/conf.d/newdomain.com.conf and remember to replace YOURIPADDRESS with your static IP address:

Code:
location / {
            index index.php index.html index.htm;
            try_files $uri $uri/ /index.php?$uri&$args;
        
        }
 
        location /internal_data/ {
        internal;
        allow 127.0.0.1;
        allow YOURIPADDRESS;
        deny all;
        }

        location /library/ {
        internal;
        allow 127.0.0.1;
        allow YOURIPADDRESS;
        deny all;
        }

If Xenforo forum is installed off public web root in it's own directory i.e. /forums at /home/nginx/domains/newdomain.com/public/forums, then you'll need to add and edit the following Nginx rewrites in /usr/local/nginx/conf/conf.d/newdomain.com.conf and remember to replace YOURIPADDRESS with your static IP address:

Code:
        location /forums/ {
            index index.php index.html index.htm;
            try_files $uri $uri/ /forums/index.php?$uri&$args;

        }

        location /forums/internal_data/ {
        internal;
        allow 127.0.0.1;
        allow YOURIPADDRESS;
        deny all;
        }

        location /forums/library/ {
        internal;
        allow 127.0.0.1;
        allow YOURIPADDRESS;
        deny all;
        }
 
So don't use additional directives through plesk, manually edit my nginx.conf for my domain? It is setup to be blah/blah/goblintimes.com/service/nginx.conf
 
Solved.

For those wondering who have this issue as well, follow instructions from help section for Friendly URLs but replace what XenForo provides with the following:
Code:
location ~ /$  {
        try_files $uri $uri/ /index.php?$uri&$args;
        index index.php index.html;
}

location /install/data/ {
        internal;
}
location /install/templates/ {
        internal;
}
location /internal_data/ {
        internal;
}
location /library/ {
        internal;
}

if (!-e $request_filename){
    rewrite ^(.*)$ /index.php break;
}

This has fixed my issue, with some trial and error as well as looking at past threads for XF 1.5 I came to this solution.
 
Top Bottom