XF 2.0 Friendly URL's with Nginx throwing 404's

entelechy

Active member
The sites running an SSL and works fine with the configuration prior to trying to get friendly urls happening.

I followed (https://xenforo.com/help/friendly-urls/), but everything except / is throwing 404's. After every modification I've restarting nginx each time.

The server block as it stands right now:

server {

root /var/www/my-forum.com/html;

index index.php index.html;

server_name my-forum.com www.my-forum.com;

location / {
try_files $uri $uri/ /var/www/my-forum.com/html/index.php?$uri&$args;
}
location /install/data/ {
internal;
}
location /install/templates/ {
internal;
}
location /internal_data/ {
internal;
}
location /library/ {
internal;
}

location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

location ~ /\.ht {
deny all;
}

listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/my-forum.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/my-forum.com/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
}
 
Last edited:

entelechy

Active member
If anyone can see any mistakes in the code above or has experience with this same issue with Nginx x Friendly URLs I'd really appreciate any advice.
 

markus68

Active member
Hi,
try the php-location block first as in the docs:
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;
}
(adjusting your socket-parameters).

I think the problem is with your
include snippets/fastcgi-php.conf;

-Markus
 

entelechy

Active member
Hi, thanks for the reply.

Adding try_files $uri =404; is not needed/possible because it's already called in include snippets/fastcgi-php.conf; (error message when adding this is:
nginx: [emerg] "try_files" directive is duplicate in /etc/nginx/snippets/fastcgi-php.conf:5

The difference between the php location block I'm using and the one in the docs that you refer to is that the docs show a setup for php-7.0 cgi only..
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;

But I'm running PHP-fpm, hence:

fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;

The inclusion of snippets/fastcgi-php.conf; is from setting up LEMP via digitalocean guidelines (https://www.digitalocean.com/commun...ux-nginx-mysql-php-lemp-stack-in-ubuntu-16-04).
 

entelechy

Active member
Or is there an incompatibility with friendly urls and fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; + includes snippets/fastcgi-php.conf; ??
 

markus68

Active member
What I wanted to recommend is to first start with the clean example-configuration provided in the XF-docs and see if that works. As you run php socket-based this change will be needed.

If that works, try to adjust your settings step by step to what you have non-working right now and see where it fails.

Friendly URLs definetly work with nginx (as I am using this setup).

-Markus
 

entelechy

Active member
Ok I've got you. Trying to just use the block as per the docs throws a 502 for all pages.

Are you using fpm? Do you have ssl? Any chance of seeing what your block looks like for reference? I've had friendly urls working on a different Nginx text forum without issue, but there's something about this configuration that's screwing with it.
 
Last edited:

entelechy

Active member
Ok so I looked through the post you just referenced, and started again from the beginning of this post.

If use..

try_files $fastcgi_script_name =404; - in the PHP block, it throws a 404 error on all pages except /

try_files $uri $uri/ /var/www/my-forum.com/html/index.php?$uri&$args; - in the PHP block, it throws a 500 error on all pages except /


The errors logged when using try_files $uri $uri/ /var/www/my-forum.com/html/index.php?$uri&$args; in the PHP block are:

[error] 3643#3643: *17 rewrite or internal redirection cycle while internally redirecting to "/var/www/my-forum.com/html/index.php",
client: <ip address removed>, server: my-forum.com, request: "GET /forums/general-discussion.19/ HTTP/1.1", host: "my-forum.com", referrer: "https://my-forum.com/"

There are no errors that get logged when try_files $fastcgi_script_name =404; is used in the PHP block, there's just 404's for all non-/ pages.

I saw in your referred thread, that the problem was showthread.php in the web root - there's issue with that in this case
 

entelechy

Active member
Thanks for the help you provided trying to solve this Markus.

For anyone else in the same position reading this in the future, I reached out to another member here who pointed out that this line was the culprit:

"try_files $uri $uri/ /var/www/my-forum.com/html/index.php?$uri&$args;"

After shortening it to "try_files $uri $uri/ /index.php?$uri&$args;" friendly URL's are functioning perfectly on the site.
 
Top