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

XF 1.1 Nginx Friendly URLs

Discussion in 'Troubleshooting and Problems' started by NielsGouman, Nov 30, 2012.

  1. NielsGouman

    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?
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    http://wiki.nginx.org/IfIsEvil

    Your WP rules are safe.



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

    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.
     
  3. NielsGouman

    NielsGouman Member

    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
     
  4. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    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.
     
  5. NielsGouman

    NielsGouman Member

    From what I could understand it's because that stuff is already set, and they don't want me to change it..
     

Share This Page