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

Friendly links with nginx

Sway

Active member
#1
I was looking through the help pages on xenforo, and this confused me a little bit.
It said put this in your configuration file
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 ~ \.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;
}
There is sites-available/default, and there is nginx.conf This looks like it belongs in default inside sites-available.

My Xenforo install is also inside my web server root. I am sick, and very out of it so a helping hand would be nice. :)
 

Jeremy P

Well-known member
#2
Here's what I use.. takes care of logging, proper expiry, friendly URLs, hiding internals, PHP, and .htaccess..

Your index directive should be set globally in nginx.conf, there's no real reason to define it in every server block.

Code:
server {
        listen 80;
 
        server_name yoursite.com;
 
        # root
        root /www/yoursite.com/public_html;
 
        # logging
        access_log /www/yoursite.com/logs/access.log combined;
        error_log /www/yoursite.com/logs/error.log error;
 
        # expires
        location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
                expires 1y;
        }
 
        # xf rewrite
        location / {
                try_files $uri $uri/ /index.php?$uri&$args;
        }
 
        # xf internals
        location ~ ^/(internal_data|library)/(.*)$ {
                internal;
        }
 
        # php     
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass 127.0.0.1:9000;
        }
 
        # hide .ht* files
        location ~ /\.ht {
                internal;
        }
}
You will want to adjust the root and logging directories to suit your needs, and as above make sure your index is set globally in nginx.conf
 

Sway

Active member
#3
Here's what I use.. takes care of logging, proper expiry, friendly URLs, hiding internals, PHP, and .htaccess..

Your index directive should be set globally in nginx.conf, there's no real reason to define it in every server block.

Code:
server {
        listen 80;
 
        server_name yoursite.com;
 
        # root
        root /www/yoursite.com/public_html;
 
        # logging
        access_log /www/yoursite.com/logs/access.log combined;
        error_log /www/yoursite.com/logs/error.log error;
 
        # expires
        location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
                expires 1y;
        }
 
        # xf rewrite
        location / {
                try_files $uri $uri/ /index.php?$uri&$args;
        }
 
        # xf internals
        location ~ ^/(internal_data|library)/(.*)$ {
                internal;
        }
 
        # php   
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass 127.0.0.1:9000;
        }
 
        # hide .ht* files
        location ~ /\.ht {
                internal;
        }
}
You will want to adjust the root and logging directories to suit your needs, and as above make sure your index is set globally in nginx.conf
I'm new to nginx so i don't really get any of this. It took me 4 hours to get php working correctly. :oops:
My site is located in /var/www/index.php
 

Sway

Active member
#7
Do you want www.iconomycraft.com to redirect to iconomycraft.com? Or the other way around? There's no technical reason to go with one over the other, it's just a personal preference.
Say you logged into my site from iconomycraft.com, and you clicked a link to www.iconomycraft.com. My quote below from a pm on my forum with Brandon Sheley says it all. I'm just here for those user friendly links though. I mean this would help too because i planned on forcing www or non www after he sent me this pm. :)

Brandon Sheley said:
you should force www or non-www

I can login to www, then remove the www and I'm not logged in anymore
this is annoying to members and isn't good for SEO ;)
 

Sway

Active member
#9
If you want i can shoot you a pm with some pastebin links of both my nginx.conf, and sites-enabled/default lol. I most likely will let this sit for a while because i'm too sick to think. :ROFLMAO: Maybe if your up for it you can give me a hand? :oops: