• 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

ChemicalKicks

Well-known member
#1
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. ?
 

ChemicalKicks

Well-known member
#2
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;
}
 
}
 

Jake Bunce

XenForo moderator
Staff member
#3
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

Well-known member
#4
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;
 

ChemicalKicks

Well-known member
#11
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".
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?
 

Deebs

Well-known member
#12
I would remove $uri/ as XenForo does not expose directories and thus is not needed. It is just a wasted test.
 

Floren

Well-known member
#14
This appears to be working for me now, how's it look to you? Is there anything you would clean up?
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?
 

Deebs

Well-known member
#15
You should only remove &uri/ as that means check for a directory. XF does not expose directories so get rid off.
 

ChemicalKicks

Well-known member
#16
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?
I'm reading through your article now.

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

ChemicalKicks

Well-known member
#17
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?