Advertisement:

Author Topic: SMF on nginx.  (Read 30538 times)

Offline viulian

  • Jr. Member
  • **
  • Posts: 235
    • Hex.ro
SMF on nginx.
« on: November 19, 2007, 02:35:51 AM »
Hi guys!

I have installed SMF on nginx. The trickiest part was getting PrettyURL SEO module to work (as the rewrite rules must be changed).

Here are the new rules that work for me:

Code: [Select]
location /smf/ {
                index index.php;
                rewrite ^(/smf)/([-_!~*'()$a-zA-Z0-9]+)/[0-9]?/?$ $1/index.php?pretty%3Bboard=$2.0 last;
                rewrite ^(/smf)/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*)/[0-9]?/?$ $1/index.php?pretty%3Bboard=$2.$3 last;

                rewrite ^(/smf)/([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/[0-9]?/?$ $1/index.php?pretty%3Bboard=$2%3Btopic=$3.0 last;
                rewrite ^(/smf)/([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*|msg[0-9]*|new)/[0-9]?/?$ $1/index.php?pretty%3Bboard=$2%3Btopic=$3.$4 last;
        }

Installation is otherwise simple, it works by default :)

nginx is a lightweight and stable web server, with low memory footprint. Works great (I have managed to install it into an Ubuntu 6.06 image running inside coLinux with 256Mb RAM - goal was to find how the system behaves in low memory conditions). I am looking for a VPS and seems that price goes up exponentially with the memory you need :)

I hope nginx to solve the issue with Apache + mod_php eating a lot of memory.

I also have Wordpress MU integrated with SMF, the rules for that I don't have yet, but I'm working on that.
You can visit my site here, where I'll post more info about the issue..

Anyway, SMF is impressive. It works like a charm!
Thank you SMF team!

Offline Nao 尚

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,928
  • Gender: Male
    • wedgebook on Facebook
    • Wedge
Re: SMF on nginx.
« Reply #1 on: November 29, 2007, 11:51:31 AM »
Sounds interesting... :) Apart from your feedback on installing PrettyURLs on your server, can you share how easy/difficult it is to install nginx as opposed to Apache? And is there anything to remember when setting up a SMF install?
I will not make any deals with you. I've resigned. I will not be pushed, filed, stamped, indexed, briefed, debriefed or numbered.

Aeva Media rocks your life.

Offline H

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 21,660
  • Gender: Male
Re: SMF on nginx.
« Reply #2 on: November 29, 2007, 01:23:15 PM »
viulian, thanks for posting these :)

I normally use lighttpd as my webserver but I've noticed that the English nginx docs are getting better now so I might give it a try :)
-H
Former Support Team Lead
                              I recommend:
Namecheap (domains)
Fastmail (e-mail)
Linode (VPS)
                             

Offline viulian

  • Jr. Member
  • **
  • Posts: 235
    • Hex.ro
Re: SMF on nginx.
« Reply #3 on: November 29, 2007, 10:40:00 PM »
Thank you for the feedback :)

Apart from compiling (plus downloading the dependencies), and setting up PHP to run as fast-cgi server, there's one think you should remember:

export PHP_FCGI_CHILDREN=2
export PHP_FCGI_MAX_REQUESTS=1000

If you do not set these variables before invoking php-cgi, your php-cgi process will die very soon without any error message. By default (I didn't check in detail though, and by default I mean without them set), php-cgi runs without any children, and it doesn't restart itself after handling a certain number of requests. And so it will die after a while.

I will post an nginx installation tutorial soon and will let you know..

Here's the forum URL (most if it is in Romanian, check it for speed and Pretty URL links).
Please remember that Blogs in the upper right doesn't work yet - I have to make the WPMU rewrite rules and I didn't have time this week.

Offline Something like that

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 2,496
  • Gender: Male
  • ]
Re: SMF on nginx.
« Reply #4 on: December 25, 2007, 06:24:41 AM »
I *just* moved my forums over to a dedicated server. But I couldn't just do that! I had to play with new stuff ;)

I also have SMF running on nginx, and I also compiled APC into PHP. Lets just say things are screaming fast :D

Offline Nao 尚

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,928
  • Gender: Male
    • wedgebook on Facebook
    • Wedge
Re: SMF on nginx.
« Reply #5 on: December 25, 2007, 07:49:02 AM »
URL URL please :)
I will not make any deals with you. I've resigned. I will not be pushed, filed, stamped, indexed, briefed, debriefed or numbered.

Aeva Media rocks your life.

Offline viulian

  • Jr. Member
  • **
  • Posts: 235
    • Hex.ro
Re: SMF on nginx.
« Reply #6 on: December 26, 2007, 02:18:26 AM »
Nice :)

Have you activated nginx-stats ?

What I like though about nginx.. is that I completed the install a month ago, and ever since the memory stays at 182Mb (I am running inside a virtual private server / open vz ) along with DJBDNS and qmail. Zero memory leaks. Impressive :)

Offline Something like that

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 2,496
  • Gender: Male
  • ]
Re: SMF on nginx.
« Reply #7 on: December 26, 2007, 02:56:35 AM »
Nice :)

Have you activated nginx-stats ?

I wasn't aware of it. I'll look into it!

Quote
What I like though about nginx.. is that I completed the install a month ago, and ever since the memory stays at 182Mb (I am running inside a virtual private server / open vz ) along with DJBDNS and qmail. Zero memory leaks. Impressive :)

Yeah, unlike lighttpd. My nginx is using about 3 MB of RAM. The PHP processes leak a little, but it's only a few MB before the 10,000 hit limit kills the process. I'm still running email on another host, but I'll change that later...

Offline viulian

  • Jr. Member
  • **
  • Posts: 235
    • Hex.ro
Re: SMF on nginx.
« Reply #8 on: April 13, 2009, 05:58:12 PM »
More than one year or so has passed since I run SMF (and gallery2 on that matter) on nginx ..

Small review: everything is almost perfect :) minus a small inconvenience related to the fcgi wrapper (php-cgi processes).

Somehow when the machine is heavily loaded, they fail and do not timeout - so I need to kill all the processes and restart. And then it works, even if the machine is still with more than 3.00 load.

However, this has only happened like 5-6 times so far.. in more than 1 year so no biggie..

Memory usage has slowly increased, probably due to the mysql databases which keep getting bigger and bigger and mysql trying to accomodate.
I am now at 200Mb compared to 170Mb a year or so ago - so I bow in respect for nginx, qmail, dropbear, djbdns, mysql and SMF. Setup is the kind of configure and forget.
 
The only weak link in it is php-cgi, but on the other hand I might need to upgrade it..

Offline Something like that

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 2,496
  • Gender: Male
  • ]
Re: SMF on nginx.
« Reply #9 on: September 12, 2009, 10:57:55 AM »
I've been using Nginx for almost two years now, and I'll never go back. It's so much faster, lighter, and solid.

Offline Schokobecher

  • Newbie
  • *
  • Posts: 2
Re: SMF on nginx.
« Reply #10 on: June 29, 2010, 05:59:56 PM »
I know this is quite old, but a new thread would be a waste.

I'm running SMF 2.0 RC3 and the 1.0 PrettyURLs Module.

My problem is that if I activate the rewrite rule for boards, the action rewrites won't work. They just redirect to the index.php.
If I comment that line out all is fine.

My rules:
Code: [Select]
#rewrite ^/([-_!~*'()$a-zA-Z0-9]+)/[0-9]?$ "/index.php?pretty;board=$1.0" last;
rewrite ^/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*)/[0-9]?/?$ "/index.php?pretty;board=$1.$2" last;
rewrite ^/([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/[0-9]?/?$ "/index.php?pretty;board=$1;topic=$2.0" last;
rewrite ^/([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*|msg[0-9]*|new)/[0-9]?/?$ "/index.php?pretty;board=$1;topic=$2.$3" last;



rewrite ^/(activate|admin|announce|ban|boardrecount|buddy|calendar|cleanperms)/?$ "/index.php?pretty;action=$1" last;
rewrite ^/(collapse|convertentities|convertutf8|coppa|deletemsg|detailedversion|display|dlattach)/?$ "/index.php?pretty;action=$1" last;
rewrite ^/(dumpdb|editpoll|editpoll2|featuresettings|featuresettings2|findmember|help|helpadmin)/?$ "/index.php?pretty;action=$1" last;
rewrite ^/(im|jsoption|jsmodify|lock|lockVoting|login|login2|logout)/?$ "/index.php?pretty;action=$1" last;
rewrite ^/(maintain|manageattachments|manageboards|managecalendar|managesearch|markasread|membergroups|mergetopics)/?$ "/index.php?pretty;action=$1" last;
rewrite ^/(mlist|modifycat|modifykarma|modlog|movetopic|movetopic2|news|notify)/?$ "/index.php?pretty;action=$1" last;
rewrite ^/(notifyboard|optimizetables|packageget|packages|permissions|pgdownload|pm|post)/?$ "/index.php?pretty;action=$1" last;
rewrite ^/(post2|postsettings|printpage|profile|profile2|quotefast|quickmod|quickmod2)/?$ "/index.php?pretty;action=$1" last;
rewrite ^/(recent|regcenter|register|register2|reminder|removetopic2|removeoldtopics2|removepoll)/?$ "/index.php?pretty;action=$1" last;
rewrite ^/(repairboards|reporttm|reports|requestmembers|search|search2|sendtopic|serversettings)/?$ "/index.php?pretty;action=$1" last;
rewrite ^/(serversettings2|smileys|smstats|spellcheck|splittopics|stats|sticky|theme|moderate)/?$ "/index.php?pretty;action=$1" last;
rewrite ^/(trackip|about:mozilla|about:unknown|unread|unreadreplies|viewErrorLog|viewmembers|viewprofile)/?$ "/index.php?pretty;action=$1" last;
rewrite ^/(verificationcode|vote|viewquery|who|\.xml)/?$ "/index.php?pretty;action=$1" last;


I'm also trying to ge the profile rewrite to work.
The original is the following:

Code: [Select]
'rule' => 'RewriteRule ^profile/([^/]+)/?$ ./index.php?pretty;action=profile;user=$1 [L,QSA]',
So I tried:

Code: [Select]
rewrite ^/(profile)/?$ "index.php?pretty;action=profile;user=$1" last;
but it results in a 404 Error.

Any clues on that?

Offline Something like that

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 2,496
  • Gender: Male
  • ]
Re: SMF on nginx.
« Reply #11 on: June 29, 2010, 07:02:14 PM »
I've personally never used quotes in my Nginx rewrites. Is it just the first 4 lines that aren't working for you?


For your profile rewrite, you didn't put the / in front of index.php.

Offline Something like that

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 2,496
  • Gender: Male
  • ]
Re: SMF on nginx.
« Reply #12 on: June 29, 2010, 07:06:12 PM »
My problem is that if I activate the rewrite rule for boards, the action rewrites won't work. They just redirect to the index.php.
If I comment that line out all is fine.

My rules:
Code: [Select]
#rewrite ^/([-_!~*'()$a-zA-Z0-9]+)/[0-9]?$ "/index.php?pretty;board=$1.0" last;

I suspect you the problem is not escaping the regular expression control characters from the string you wish to capture. Try this:

Code: [Select]
rewrite ^/([\-\_\!\~\*\'\(\)\$a-zA-Z0-9]+)/[0-9]?$ "/index.php?pretty;board=$1.0" last;

Offline Schokobecher

  • Newbie
  • *
  • Posts: 2
Re: SMF on nginx.
« Reply #13 on: June 29, 2010, 11:28:17 PM »
The missing / was a typo.
Now it always stays on the index.php

The Forum Rewrite still breaks the action rewrites.
I'm so puzzled.

Offline viulian

  • Jr. Member
  • **
  • Posts: 235
    • Hex.ro
Re: SMF on nginx.
« Reply #14 on: June 30, 2010, 05:47:48 PM »
I have the same issue - but is not bothering me - I live happily with a very old PrettyURL.
First, the module is for search engine optimization. I want to be ranked by the content and not by profile/management/etc keywords. So I left them all off.

nginx has a 'debug_connection' directive, which you can activate for your IP in the 'events' section of nginx.conf.
It will show why it doesn't match the URLs and what is attempting to do - hopefully it can help (I mean it helped me a lot when debugging those first 4 lines...)

Offline Kill Em All

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 8,144
  • Gender: Male
  • Something has to go wrong. Just has to.
    • KEAGaming
Re: SMF on nginx.
« Reply #15 on: July 26, 2010, 11:01:26 PM »
Schokobecher, I'm going to mark this as solved, if you have any further problems please start your own topic.

@viulian, very glad your happy with it.
My Site: KEAGaming.com

Manual Installation of Mods
Prevent Spam and Forum Attacks
Please do not PM or email me for support unless offered, help should be publicly displayed to others.