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

Friendly links with nginx

Discussion in 'Server Configuration and Hosting' started by Sway, Jan 13, 2013.

  1. Sway

    Sway Active Member

    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. :)
     
  2. Jeremy P

    Jeremy P Well-Known Member

    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
     
    Volion and Jake Bunce like this.
  3. Sway

    Sway Active Member

    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
     
  4. Jeremy P

    Jeremy P Well-Known Member

    What's your site's URL?
     
  5. Sway

    Sway Active Member

  6. Jeremy P

    Jeremy P Well-Known Member

    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.
     
    Brandon Sheley likes this.
  7. Sway

    Sway Active Member

    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 likes this.
  8. Jeremy P

    Jeremy P Well-Known Member

    Well might as well get it taken care of, it's very simple. Which do you want to force? I will drop a rule for it in the config I give you.
     
    Brandon Sheley likes this.
  9. Sway

    Sway Active Member

    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:
     
  10. Jeremy P

    Jeremy P Well-Known Member

    Yeah of course, send me a PM :)
     
    Sway likes this.
  11. Sway

    Sway Active Member

    Sent. :)
     

Share This Page