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

Can't get nginx & friendly URLS working

Discussion in 'Troubleshooting and Problems' started by ChemicalKicks, Nov 30, 2011.

  1. ChemicalKicks

    ChemicalKicks Well-Known Member

    Maybe it's because I've spent the last 48 hours doing a crash course in Ubuntu and I'm very tired at the moment but I'm just stuck and no amount of Googling is helping me past this point.

    Has to be my config, does this look right or are there obvious errors? Site works fine with friendly URLS turned off.

    Code:
    server {
        server_name www.the-sps.net the-sps.net;
        access_log /srv/www/the-sps.net/logs/access.log;
        error_log /srv/www/the-sps.net/logs/error.log;
        root /srv/www/the-sps.net/public_html;
     
    location /srv/www/the-sps.net/public_html {
        try_files $uri $uri/ /srv/www/the-sps.net/public_html/index.php?$uri&$args;
        index index.php index.html;
    }
     
    location /srv/www/the-sps.net/public_html/internal_data/ {
        internal;
    }
    location /srv/www/the-sps.net/public_html/library/ {
          internal;
    }
     
    location ~ \.php$ {
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
     
    }
    
    Also how do I rediect http://the-sps.net to www. ?
     
  2. ChemicalKicks

    ChemicalKicks Well-Known Member

    Well got this almost figured out, the conf below allows me to have full friendly urls on, can land on the index and it's just example.com without the /index.php but trying to login/logout or do anything throws a 404 or 403

    Code:
    server {
        server_name www.the-sps.net the-sps.net;
        access_log /srv/www/the-sps.net/logs/access.log;
        error_log /srv/www/the-sps.net/logs/error.log;
        root /srv/www/the-sps.net/public_html;
     
    location / {
            index index.html index.htm index.php;
        }
     
    location /srv/www/the-sps.net/public_html {
        try_files $uri $uri/ /srv/www/the-sps.net/public_html/index.php?$uri&$args;
        index index.php index.html;
    }
     
    location /srv/www/the-sps.net/public_html/internal_data/ {
        internal;
    }
    location /srv/www/the-sps.net/public_html/library/ {
          internal;
    }
     
    location ~ \.php$ {
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
     
    }
    
     
  3. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    You have specified full server paths for the locations. That won't work. You need to use web paths. Try this:

    Code:
    server {
    	server_name www.the-sps.net the-sps.net;
    	access_log /srv/www/the-sps.net/logs/access.log;
    	error_log /srv/www/the-sps.net/logs/error.log;
    	root /srv/www/the-sps.net/public_html;
    
    location / {
    	index index.html index.htm index.php;
    }
    
    location / {
    	try_files $uri $uri/ /index.php?$uri&$args;
    	index index.php index.html;
    }
    
    location /internal_data/ {
    	internal;
    }
    location /library/ {
    	internal;
    }
    
    location ~ \.php$ {
    	fastcgi_pass    127.0.0.1:9000;
    	fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    	include         fastcgi_params;
    }
    
    For reference:

    http://xenforo.com/help/friendly-urls/
    http://wiki.nginx.org/NginxHttpCoreModule#location
     
    ChemicalKicks likes this.
  4. ChemicalKicks

    ChemicalKicks Well-Known Member

    Hey Jake,

    Still having problems with this, tried the web paths like you suggested but nginx is throwing up errors with it.

    EDIT: Tweaked a bit more and started looking at the lines referencing the index, as in why did I have to sections referencing the index. Took out the most top bit so now it looks like this and works.

    Code:
    server {
        server_name www.the-sps.net the-sps.net;
        access_log /srv/www/the-sps.net/logs/access.log;
        error_log /srv/www/the-sps.net/logs/error.log;
        root /srv/www/the-sps.net/public_html;
     
    location / {
        try_files $uri $uri/ /index.php?$uri&$args;
        index index.php index.html;
    }
     
    location /internal_data/ {
        internal;
    }
    location /library/ {
        internal;
    }
     
    location ~ \.php$ {
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
     
    }
    EDIT: 2

    I just can't get the non www redirecting correctly. I wasnt http://the-sps.net to be rewritten with as http://www.the-sps.net but I'm just not getting it.

    Code:
    server {
            if ($host = 'http://the-sps.net' ) {
            rewrite  ^/(.*)$  http://www.the-sps.net/$1  permanent;
    }
        server_name www.the-sps.net the-sps.net;
        access_log /srv/www/the-sps.net/logs/access.log;
        error_log /srv/www/the-sps.net/logs/error.log;
        root /srv/www/the-sps.net/public_html;
     
  5. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    $host should not include the protocol. Try this:

    Code:
    if ($host = 'the-sps.net' )
    
     
  6. ChemicalKicks

    ChemicalKicks Well-Known Member

    Thanks Jake,

    See if I put the long url in with www it works but the putting the non www url in doesn't result in the redirect. So no joy.
     
  7. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

  8. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

  9. ChemicalKicks

    ChemicalKicks Well-Known Member

    I think it's just got something to do with the way I have it set out, tried as you suggested with the double quotes too :(
     
  10. Floren

    Floren Well-Known Member

    Proper configuration. Use:
    Code:
    	location / {
    		try_files		$uri $uri/ /index.php?$uri&$args;
    	}
    Make sure you read the entire article, Nginx is not a "Copy/Paste from Internet thingie".
     
  11. ChemicalKicks

    ChemicalKicks Well-Known Member

    Code:
    server {
            if ($host = 'the-sps.net' ) {
            rewrite  ^/(.*)$  http://www.the-sps.net/$1  permanent;
    }
        server_name www.the-sps.net the-sps.net;
        access_log /srv/www/the-sps.net/logs/access.log;
        error_log /srv/www/the-sps.net/logs/error.log;
        root /srv/www/the-sps.net/public_html;
     
    location / {
        try_files $uri $uri/ /index.php?$uri&$args;
        index index.php index.html;
    }
     
    location /internal_data/ {
        internal;
    }
    location /library/ {
        internal;
    }
     
    location ~ \.php$ {
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
     
    location /phpmyadmin {
                  root /usr/share/;
                  index index.php index.html index.htm;
                  location ~ ^/phpmyadmin/(.+\.php)$ {
                          try_files $uri =404;
                          root /usr/share/;
                          fastcgi_pass 127.0.0.1:9000;
                          fastcgi_index index.php;
                          fastcgi_param SCRIPT_FILENAME $request_filename;
                          include /etc/nginx/fastcgi_params;
                  }
                  location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
                          root /usr/share/;
                  }
            }
            location /phpMyAdmin {
                  rewrite ^/* /phpmyadmin last;
            }
     
    }
    
    This appears to be working for me now, how's it look to you? Is there anything you would clean up?
     
  12. Deebs

    Deebs Well-Known Member

    I would remove $uri/ as XenForo does not expose directories and thus is not needed. It is just a wasted test.
     
  13. ChemicalKicks

    ChemicalKicks Well-Known Member

    Hey, thanks for pointing that out. Before I go ahead and remove &uri, there's 7 instances, should I remove them all?
     
  14. Floren

    Floren Well-Known Member

    It is 95% bad, not to mention that anyone can hack your server.
    You did not read the tutorial at all, is it hard to use the configuration posted into tutorial and solve all your problems?
     
  15. Deebs

    Deebs Well-Known Member

    You should only remove &uri/ as that means check for a directory. XF does not expose directories so get rid off.
     
  16. ChemicalKicks

    ChemicalKicks Well-Known Member

    I'm reading through your article now.

    Most of it is it is just lifted from the xenforo help files :eek:
     
  17. ChemicalKicks

    ChemicalKicks Well-Known Member

    To clarify... most of my conf is lifted from the xenforo help files, but I see a lot of stuff missing compared to your example.

    Floren, I've only ever had my hands on a server for all of 4 days now so you'll have to go a bit easy on me. What would you suggest to lock down the server?
     
  18. Floren

    Floren Well-Known Member

    Open a thread on our forums, so we go through all issues you have now.
     

Share This Page