Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Tue Apr 06, 2010 3:40 am 
Offline
Junior Member

Joined: Mon Mar 29, 2010 3:11 pm
Posts: 48
Website: http://www.tamerax.com
Location: Montreal, Quebec
hey!

I have 2 questions for nginx users.

1) I'm trying to setup my joomla server onto my new linode running NGINX and after much (like days) of searching and testing, I finally have a config that works with with SEF url plugins...sorta. I was using an apache system on the old server and it used mod_rewrite and life was fine in terms of SEF. Since NGINX doesn't have mod_rewrite, I found something that works BUT it constantly leaves index.php in the urls.

ex: http://mysite.com/index.php/forum

i want it to be just http://mysite.com/forum but without mod_rewrite it doesn't seem to be possible in joomla that i'm aware of. I know in wordpress it IS possible but I have to use a plugin.

Here is my config file:
Code:
server {
  listen 80;
  server_name mysite.com www.mysite.com;



            access_log /home/public_html/mysite.com/log/access.log;
            error_log /home/public_html/mysite.com/log/error.log;
root   /home/public_html/mysite.com/public/;

  large_client_header_buffers 4 8k; # prevent some 400 errors

  index           index.php index.html;
  fastcgi_index   index.php;

  location / {
    expires 30d;
    error_page 404 = @joomla;
    log_not_found off;
  }
# Rewrite
location @joomla {
  rewrite ^(.*)$ /index.php?q=last;
}

# Static Files
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ {
  access_log        off;
  expires           30d;
}
  # PHP
  location ~ \.php {
    keepalive_timeout 0;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include /usr/local/nginx/conf/fastcgi_params;
            fastcgi_param SCRIPT_FILENAME /home/public_html/mysite.com/public/$fastcgi_script_name;
}
}


2) second question should be easy but i can't get it to work.
I want to use the same config I posted above and have either mysite.com or www.mysite.com both forward to mysite.com/portal.

Basically when you hit up the front page with or without the www, it all gets forwarded to a sub directory on the server I called Portal.

I have tried several variations of:
Code:
 rewrite ^/(.*) http://www.example.com/portal/$1 permanent;


but it usually ends with firefox telling me there is some crazy loop happening the address bar saying something like mysite.com/portalportalportalportalportal.........on and on.

So, any help on either of these issues would be awesome!!
Thanks!!


Top
   
 Post subject:
PostPosted: Tue Apr 06, 2010 6:14 am 
Offline
Senior Member

Joined: Sun Mar 07, 2010 7:47 pm
Posts: 1970
Website: http://www.rwky.net
Location: Earth
1) Can you provide the mod_rewrite rules and I'll try and convert them for you.

2)
Try this

Code:
rewrite  / /portal permanent;


that should rewrite just / which is the root of the site but it won't rewrite /index.php or /whatever.


Top
   
 Post subject:
PostPosted: Tue Apr 06, 2010 12:18 pm 
Offline
Junior Member

Joined: Mon Mar 29, 2010 3:11 pm
Posts: 48
Website: http://www.tamerax.com
Location: Montreal, Quebec
awesome thanks :)

Code:
########## Begin - Rewrite rules to block out some common exploits
## If you experience problems on your site block out the operations listed below
## This attempts to block the most common type of exploit `attempts` to Joomla!
#
## Deny access to extension xml files (uncomment out to activate)
#<Files ~ "\.xml$">
#Order allow,deny
#Deny from all
#Satisfy all
#</Files>
## End of deny access to extension xml files
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]
#
########## End - Rewrite rules to block out some common exploits

#  Uncomment following line if your webserver's URL
#  is not directly related to physical file paths.
#  Update Your Joomla! Directory (just / for root)

# RewriteBase /


########## Begin - Joomla! core SEF Section
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
#
########## End - Joomla! core SEF Section


Top
   
 Post subject:
PostPosted: Tue Apr 06, 2010 4:05 pm 
Offline
Junior Member

Joined: Mon Mar 29, 2010 3:11 pm
Posts: 48
Website: http://www.tamerax.com
Location: Montreal, Quebec
the rewrite rule didn't work :(

seems like it should be fairly easy to have mysite.com and www.mysite.com both point to the same sub-directory :(

alas it's beyond me.


Top
   
 Post subject:
PostPosted: Tue Apr 06, 2010 5:17 pm 
Offline
Senior Member

Joined: Tue Apr 29, 2008 6:26 pm
Posts: 58
Website: http://blog.shadypixel.com/
Are you using apache or nginx?

You want something like:

rewrite ^/(.*) http://www.example.com/portal/$1 permanent;

except with nginx you want to put that in an "if" block and with apache you want to add a rewritecond

Basically, you only want to do that rewrite if the host part of the request is not already www.example.com or the request uri doesn't already start with portal

otherwise, you'll redirect the visitor every they make a request (infinite loop which apparently firefox detected)


Top
   
 Post subject:
PostPosted: Tue Apr 06, 2010 9:18 pm 
Offline
Junior Member

Joined: Mon Mar 29, 2010 3:11 pm
Posts: 48
Website: http://www.tamerax.com
Location: Montreal, Quebec
yup thats what i want. I'm using nginx so what would be the full bit of code including the if statement.


Top
   
 Post subject:
PostPosted: Tue Apr 06, 2010 10:09 pm 
Offline
Senior Member

Joined: Tue Apr 29, 2008 6:26 pm
Posts: 58
Website: http://blog.shadypixel.com/
well, this isn't ideal because potentially it could be 2 redirects, but:

Code:
if ($host != www.example.com) {
    rewrite ^/(.*)$ http://www.example.com/$1 permanent;
}
if ($request_uri !~ ^/portal/.*$) {
    rewrite ^/(.*)$ http://www.example.com/portal/$1 permanent;
}


untested but that should work.


Top
   
 Post subject:
PostPosted: Tue Apr 06, 2010 10:44 pm 
Offline
Junior Member

Joined: Mon Mar 29, 2010 3:11 pm
Posts: 48
Website: http://www.tamerax.com
Location: Montreal, Quebec
didn't work :(

www.example.com takes me to the firefox error page talking about a loop.

example.com takes me to the default "Welcome to nginx!" page.

neither of them redirected to /portal :(


Top
   
 Post subject:
PostPosted: Tue Apr 06, 2010 11:39 pm 
Offline
Senior Member

Joined: Sun Mar 07, 2010 7:47 pm
Posts: 1970
Website: http://www.rwky.net
Location: Earth
This bit:
Code:
########## Begin - Joomla! core SEF Section 
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php

Should translate into:
Code:
if (!-e $request_filename)
{
set $redirect 'y';
}

if ($request_uri ~ (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$)
{
set $redirect $redirect'y';
}

if ($request_uri ~ ^/index.php)
{
set $redirect '';
}

if ($redirect = 'yy')
{
   rewrite (.*) /index.php;
}



As for your portal problem, does the /portal directory actually exist and if so what's it's index file?


Top
   
 Post subject:
PostPosted: Wed Apr 07, 2010 12:05 am 
Offline
Junior Member

Joined: Mon Mar 29, 2010 3:11 pm
Posts: 48
Website: http://www.tamerax.com
Location: Montreal, Quebec
i will try those rules out and get back to you. thanks :D

yes, portal does actually exist. portal is actually where my joomla installation sits (as opposed to my root) so index.php is the main file in there there.


Top
   
 Post subject:
PostPosted: Wed Apr 07, 2010 1:26 am 
Offline
Senior Member

Joined: Sun Mar 07, 2010 7:47 pm
Posts: 1970
Website: http://www.rwky.net
Location: Earth
Ohhh well that explains why you're rules aren't working quite right.

What's in the root directory?


Top
   
 Post subject:
PostPosted: Wed Apr 07, 2010 1:58 am 
Offline
Junior Member

Joined: Mon Mar 29, 2010 3:11 pm
Posts: 48
Website: http://www.tamerax.com
Location: Montreal, Quebec
in the root is nothing like an index file which is why it gives me a 403 Forbidden error :P I'm debating putting an index.php file with a php 301 redirect in there as a temporary solution to this.

but yeah...nothing in root except a few audio files


Top
   
 Post subject:
PostPosted: Thu Apr 08, 2010 12:41 am 
Offline
Senior Member

Joined: Sun Mar 07, 2010 7:47 pm
Posts: 1970
Website: http://www.rwky.net
Location: Earth
Try this for your entire config I've added comments about what does what

Code:
server { 
   listen 80;
   server_name mysite.com www.mysite.com;
   access_log /home/public_html/mysite.com/log/access.log;
   error_log /home/public_html/mysite.com/log/error.log;
   root   /home/public_html/mysite.com/public/;

     large_client_header_buffers 4 8k; # prevent some 400 errors

     index           index.php index.html;
     fastcgi_index   index.php;
   
   #redirect mysite.com and www.mysite.com to /portal
   location = / {
   rewrite (.*) /portal last;
   }

   #pass php files to fastcgi
   location ~ \.php$
   {
               fastcgi_pass 127.0.0.1:9000;
               fastcgi_index index.php;
               include /usr/local/nginx/conf/fastcgi_params;
               fastcgi_param SCRIPT_FILENAME /home/public_html/mysite.com/public/$fastcgi_script_name;
      #set expires to 0 to stop caching of php files
      expires 0;
   }
   
   #files in the /portal dir
   location ~ ^/portal
   {
   #set expires to 30d to cache static files
   expires 30d;
   #file doesn't exist, will need to be sent to php
   if (!-e $request_filename)
   {
   rewrite ^/portal/(.*)$ /index.php?q=$1 last;
   }
   }
}


I've not tested it (since I don't have joomla) but it "should" work. If it doesn't then I'd have to have a look at your setup to get it to work.


Top
   
 Post subject:
PostPosted: Thu Apr 08, 2010 1:24 am 
Offline
Junior Member

Joined: Mon Mar 29, 2010 3:11 pm
Posts: 48
Website: http://www.tamerax.com
Location: Montreal, Quebec
:D all the redirects seem to work perfectly!!!! thank you!!

now i gotta sort out how to make my SEF urls work properly but i think i need someone with joomla background to do that. Basicly, I think i have to trick joomla into think mod_rewrite is there so it takes index.php out of the urls like it does for wordpress.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group