XF 1.1 Nginx Friendly URLs

NielsGouman

Member
So I've found this: http://xenforo.com/help/friendly-urls/ and I've tried adding that code over at my host.. And the host didn't allow that in my configuration.

Asked around and they said I'm not allowed to change location ~ \.php$, so I left that part out. Now the configuration could be saved, but all pages gave 404's.

Being the "never even heard of Nginx" guy I just tried leaving out other stuff, googling, and mixing in other code I could find. Eventually I fixed it by copying the friendly URLs code I used over at my WordPress install.. which is like so:

Code:
        location / {
            if (!-e $request_filename) {
                rewrite ^(.+)$ / last;
                break;
            }
        }

This works fine. BUT I've read all over this forum that "if" is evil, so how can I fix that?
 
http://wiki.nginx.org/IfIsEvil

The only 100% safe things which may be done inside if in location context are:

return ...;
rewrite ... last;

Your WP rules are safe.

Asked around and they said I'm not allowed to change location ~ \.php$, so I left that part out.


In that case try changing XenForo's nginx rules to this (add the red code):

Rich (BB code):
location /xf/ {
	try_files $uri $uri/ /xf/index.php?$uri&$args;
	index index.php index.html;
}

location /xf/internal_data/ {
	internal;
}
location /xf/library/ {
       internal;
}

location ~ ^/xf/.+\.php$ {
	try_files $uri /xf/index.php
	fastcgi_pass    127.0.0.1:9000;
	fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
	include         fastcgi_params;
}

I am not setup to test this, but the idea is to limit the rule to php files in the /xf directory (change to match the name of your xf directory) which may agree with your host and should still function.
 
Thanks Jake :)

XF is installed in the root directory, so I've changed it to this:
Code:
location / {
    try_files $uri $uri/ /index.php?$uri&$args;
    index index.php index.html;
}
 
location /internal_data/ {
    internal;
}
location /library/ {
      internal;
}
 
location ~ ^/.+\.php$ {
    try_files $uri /xf/index.php
    fastcgi_pass    127.0.0.1:9000;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

and again I'm not allowed to save this config, because of that last section
 
Why won't your host let you change that?

I have almost no experience with nginx, but I believe that last section simply defines the fastcgi handler for PHP scripts. Your server may already have this location defined.
 
Top Bottom