• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XenForo SEO-friendly url's issue with Plesk and nginx

#1
Is there anyone using the combo Plesk and nginx ?
I need some help :oops:

I recently switched from Apache to nginx.
To be honest: I do not have any experience with nginx. All my site were on Apache. But now I wanted to know if nginx is that fast as everyone says ;)

Ok, my VPS is running Ubuntu 12 LTS, Plesk Onyx (17 Update #18) for the admin things.
Plesk offers an easy way to enable nginx: https://support.plesk.com/hc/en-us/articles/213944825-How-to-enable-Nginx-reverse-proxy-in-Plesk
I followed all the steps, than deactivated proxy mode. Now nginx is completely serving all the content.
Plesk automatically creates the nginx.conf files. All additional directives have to be put into a form in Plesk, that creates a vhost_nginx.conf, that is included in the Plesk created domain specific nginx.conf .

The automatically created domain specific nginx.conf:
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 1.2.3.4:443 ssl;

    server_name domain.com;
    server_name www.domain.com;
    server_name ipv4.domain.com;

    ssl_certificate             /opt/psa/var/certificates/certjdLQBMx;
    ssl_certificate_key         /opt/psa/var/certificates/certjdLQBMx;

    client_max_body_size 128m;

    root "/var/www/vhosts/domain.com/httpdocs/folder";
    access_log "/var/www/vhosts/system/domain.com/logs/proxy_access_ssl_log";
    error_log "/var/www/vhosts/system/domain.com/logs/proxy_error_log";

    location ~ ^/plesk-stat/ {
        auth_basic "Domain statistics";
        auth_basic_user_file "/var/www/vhosts/system/domain.com/pd/d..httpdocs@plesk-stat";

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

        location ~ /$ {
            index index.html index.cgi index.pl index.php index.xhtml index.htm index.shtml;
        }
    }

    location ~ ^/~(.+?)(/.*?\.php)(/.*)?$ {
        alias /var/www/vhosts/domain.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/domain.com/php-fpm.sock";
        include /etc/nginx/fastcgi.conf;
    }

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

    location ~ /$ {
        index index.html index.cgi index.pl index.php index.xhtml index.htm index.shtml;
    }

    include "/var/www/vhosts/system/domain.com/conf/vhost_nginx.conf";
}
And that's what I added in the "Additional nginx directives" section (based on https://xenforo.com/help/friendly-urls/) and is now in the /var/www/vhosts/system/domain.com/conf/vhost_nginx.conf:
Code:
location / {
    try_files $uri $uri/ /index.php?$uri&$args;
    index index.php index.html;
}

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;
}
That worked as long as didn't active SEO-friendly URL's in XenForo.
If I activated SEO-friendly URL's, the forum main page is ok, but the server responded with a 404 for an index.html for every thread or post link.
E.g. a request for a post https://www.domain.com/posts/9876 is not answered with https://www.domain.com/threads/title-of-the-thread.123/page-3#post-9876 but with a missing https://www.domain.com/posts/9876/index.html.

Based on suggestion from Plesk support I removed the 2nd part ("location ~ \.php$ ...") and changed the first part. Now the vhost_nginx.conf looks likes this:
Code:
if (!-e $request_filename){
    rewrite ^(.*)$ /index.php break;
}
Now the SEO-friendly URL's are working.
But I do have some side-effects: my munin reporting (formerly available under https://www.domain.com/munin) is not available anymore, returns only a 404. The same for the plesk stats (https://www.domain.com/plesk-stat).
But the worst thing is: I have lots of errors in the log file like this:
2017/03/14 21:22:24 [error] 10031#0: *538916 "/var/www/vhosts/domain.com/httpdocs/folder/threads/thread-title.620/index.html" is not found (2: No such file or directory), client: xx.xx.xx.xxx, server: www.domain.com, request: "GET /threads/thread-title.620/ HTTP/1.1", host: "domain.com", referrer: "https://www.domain.com/forums/forum-title.30/"
So, again, everyone running the same combo and would like to share the configs ?
Any help on this is highly appreciated.
I am going crazy ^^
 
#5
Thanks for your answers @Solidus and @Mouth

I run the same setup for a long time and never got it working.
:( Not the answer I wanted to have ;)

You have too many duplicate location directives for php.
Refer https://talk.plesk.com/threads/xenforo-nginx-friendly-urls.331330/
Ok, but what's to be removed ?
The domain specific nginx.conf was created by Plesk and shouldn't be edited.
If I remove the XenForo part
Code:
if (!-e $request_filename){
    rewrite ^(.*)$ /index.php break;
}
from vhost_nginx.conf the file is empty. All the config is then in the domain specific nginx.conf, but SEO-friendly URL's not working.

That's my thread, it didn't help.
Did you get it solved ? At least your WWE board has SEO-friendly URL's. What did you do ? Switch to Apache ? :eek:
 

Mouth

Well-known member
#6
The domain specific nginx.conf was created by Plesk and shouldn't be edited.
[...]
All the config is then in the domain specific nginx.conf, but SEO-friendly URL's not working.
Then the plesk config is inadequate, and if your shouldn't edit their file then plesk is your issue, not nginx.
Here's what I have, that works fine ...
Code:
    location ~ [^/]\.php(/|$) {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        if (!-f $document_root$fastcgi_script_name) {
                return 404;
        }
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        include /etc/nginx/fastcgi_params;
    }
 

optrex

Well-known member
#7
I had a similar issue running vpssim = I used this as it was cheaper than plesk, which I came from. I was just going around in circles with trying to fault find a new server after having an identical installation on my existing server work fine for years. Turned out that a couple of things broke with different php upgrades and in the end I actually ended up switching to centmin mod. Great thing is installing xenforo on centmin with nginx is step by step documented. It was relatively easy and supported well. You could try that.
 
#8
In Plesk, there is a settings box where one would input nginx directives. Used to be under Apache & nginx settings, but not sure for Onyx. That is generally the best place to input directives if you're running Plesk.

You might try running a test-instance of Xenforo on a DigitalOcean VM, where you can edit the nginx directives yourself, try out the options shown in the XF manual until they work properly:

https://xenforo.com/help/friendly-urls/

I run Litespeed on XF, but have one Wordpress site running on nginx at DigitalOcean - it's nginx directives are extensive :eek:
 

Solidus

Well-known member
#9
In Plesk, there is a settings box where one would input nginx directives. Used to be under Apache & nginx settings, but not sure for Onyx. That is generally the best place to input directives if you're running Plesk.

You might try running a test-instance of Xenforo on a DigitalOcean VM, where you can edit the nginx directives yourself, try out the options shown in the XF manual until they work properly:

https://xenforo.com/help/friendly-urls/

I run Litespeed on XF, but have one Wordpress site running on nginx at DigitalOcean - it's nginx directives are extensive :eek:
That doesn't work.

Invalid nginx configuration: nginx: [emerg] duplicate location "/" in /var/www/vhosts/system/domain.com/conf/vhost_nginx.conf:1 nginx: configuration file /etc/nginx/nginx.conf test failed
 

Anthony Parsons

Well-known member
#10
XF NGINX server {} requirements, whilst some are not relevant, take note of the /install and /internal_data and /library:

Code:
location /install/data/ {
   internal;
}
location /install/templates/ {
   internal;
}
location /internal_data/ {
   internal;
}
location /library/ {
   internal;
}
The root path additionally requires something:
Code:
try_files $uri $uri/ /index.php?$uri&$args;
See: https://xenforo.com/help/friendly-urls/
 
#11
This is what I have with Plesk 17 and nginx (without apache).

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

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

location ~ /(internal_data|library) {
    internal;
}

location ~ \.php$ {
    fastcgi_pass   unix:/tmp/php.socket;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include fastcgi_params;
}

For those using Wordpress on root domain and xenforo in /forum
Code:
#WordPress nginx rewrite:

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

#Xenforo nginx rewrite:
if (!-e $request_filename){
    rewrite ^(/forum/.*)$ /forum/index.php break;
}
Those above additional nginx directives work in conjunction (active at the same time).
I know, if is evil.
All other directives will result in 404 errors either for Wordpress or Xenforo
 

Solidus

Well-known member
#12
This is what I have with Plesk 17 and nginx (without apache).

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

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

location ~ /(internal_data|library) {
    internal;
}

location ~ \.php$ {
    fastcgi_pass   unix:/tmp/php.socket;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include fastcgi_params;
}

For those using Wordpress on root domain and xenforo in /forum
Code:
#WordPress nginx rewrite:

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

#Xenforo nginx rewrite:
if (!-e $request_filename){
    rewrite ^(/forum/.*)$ /forum/index.php break;
}
Those above additional nginx directives work in conjunction (active at the same time).
I know, if is evil.
All other directives will result in 404 errors either for Wordpress or Xenforo

Unable to restart service: Unable to manage service by nginx_control: ('restart', 'nginx'). Error: /usr/local/psa/admin/sbin/nginx-config execution failed: nginx: [emerg] "if" directive is not allowed here in /etc/nginx/plesk.conf.d/ip_default/site.net.conf:1 nginx: configuration file /etc/nginx/nginx.conf test failed
 

Solidus

Well-known member
#13
I'm wondering where you put that code, because Plesk panel won't accept it because of location / and website_ip_default.conf results in the above error.
 

Anthony Parsons

Well-known member
#14
#Xenforo nginx rewrite: if (!-e $request_filename){ rewrite ^(/forum/.*)$ /forum/index.php break; }
You don't need to be evil, because you can fix the default XF location using standard NGINX rules (red):

location /forum/ {
try_files $uri $uri/ /forum/index.php?$uri&$args;
}
 
#15
I'm wondering where you put that code, because Plesk panel won't accept it because of location / and website_ip_default.conf results in the above error.
You can put this in Additional nginx directives . If you can't, I am sure you are using some other settings. Please be careful with copy and paste and make sure Plesk is not altering the additional nginx directives when inserting those rules. It is very picky.


I am not using proxy mode and ticked Serve static files directly by nginx


location /forum/ {
try_files $uri $uri/ /forum/index.php?$uri&$args;
}
This will result in 404 Not found for single threads. Your suggestions will work without Wordpress rewrite rules.
 

Anthony Parsons

Well-known member
#16
I keep forgetting, this is Plesk and nginx is only a proxy, not web server. What I had above was for the web server, as that is what I use with Wordpress frontend and forum in folder using nginx as the web server.