We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20843
    • 6 Posts
    Hey everyone,

    I’m new here, just migrated over to MODx. I was writing a CMS from scratch about a year ago, at another job, I wish I had discovered MODx then! Great software.

    Anyway, now to give back a little bit. I run my webserver using nginx, which like lighttpd, is another sweet web server. I had to create the rewrite rules so MODx will work. Here they are...

    server{
        listen                80;
        server_name           mysite.com;
    
        root /path/to/webroot;
    
        location / {
            root /path/to/webroot;
            index index.php index.html;
    
            # This is the important part - map any extension of
            # /blahblahblah that doesn't exist to index.php
    
            if (!-e $request_filename) {
                    rewrite ^(.*)$ /index.php?q=$1 last;
            }
        }
    
        # This is using spawn-fcgi for PHP processes
        # This may differ for your
        location ~ \.php(.*)$ {
            include /etc/nginx/conf/fastcgi_params;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /path/to/webroot/$fastcgi_script_name;
        }
    }
    


    Cheers, I hope this helps someone!

    admin: topic clarified for future reference
    • How does nginx compare to Apache, Zeus, lightty and others? Would love to hear about how you’re using it. smiley
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 20843
        • 6 Posts
        I’m running on a 256mb VPS from slicehost, so I’m trying to squeeze every bit of performance out of the box.

        All of our servers at work are running apache, except for dev server which we are trying out nginx on for porting it to our live boxes, and nginx out performes Apache by a looongshot. Barely see CPU budge under load, but the more important is memory usage, nginx in our tests, per request used much less memory. On my VPS, using Apache first, the swap memory would be eaten up under moderate load, under heavy load, with nginx, it’s barely touched the swap (heavy load for me is about 30 users on concurrently). I’m a bit of a memory freak, in my PHP apps pretty much lazy-loading everything for efficiency. Apache was using 30-40mb per thread (off the top of my head), nginx was about 5-6 mb (total though, # off the top of my head, but close)

        Versus lighttpd, nginx had lesser memory usage (I don’t have numbers, heh, but if you search apache vs nginx, or nginx vs lighttpd there’s a ton of benchmarks), but from what I understood they were largely similar in terms of performance. I ended up going with nginx, since lighttpd was crashing, but that was probably due to something I was doing wrong, but that and I liked the rewrite rules a little better.

        Against Zeus, I’m not sure, I haven’t used it.

        I just searched, the main article I used was:
        http://hostingfu.com/article/nginx-vs-lighttpd-for-a-small-vps

        Either way, I’m much happier over Apache, and no crazy httpd.conf file to mess with. I like nginx’s rewrite rules much better smiley I was checking out lightspeed webserver too, but don’t have a spare server to really bench it. I’d rather code wink
        • What about all the Apache modules, like GD and whatnot?
            Ryan Thrash, MODX Co-Founder
            Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
            • 20843
            • 6 Posts
            Well GD is compiled/linked into PHP, so all the PHP components do work perfectly as normal. Nothing has to change in your coding.

            location ~ \.php(.*)$ {
                    include /etc/nginx/conf/fastcgi_params;
                    fastcgi_pass  127.0.0.1:9000;
                    fastcgi_index index.php;
                    fastcgi_param SCRIPT_FILENAME /path/to/webroot/$fastcgi_script_name;
                }


            That passes any php scripts for parsing to fcgi/php. Nginx and lighttpd have their own equivalents on Apache modules, like mod_rewrite is just rewrite in nginx, etc. There’s also this http://php-fpm.anight.org/, which I’m about to install this weekend.

            If you get a chance, check it out! I’m sure it would make a noticeable difference with your hosting here. Youtube uses lighttpd IIRC

            http://interfacelab.com/nginx-php-fpm-apc-awesome/
            • Keep us informed as to how this goes. This is really cool. smiley
                Ryan Thrash, MODX Co-Founder
                Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                • 22176
                • 32 Posts
                totally agree with Nabeel

                Serving a MODx site amongst several others (a few WordPress, others non-platform) using Nginx and it doesn’t break a sweat. Can’t pretend to have huge traffic but between all probably average c. 100 simultaneous users, and using lots of scripts.

                Am about to go build a new community site using BuddyPress and looking forward to pushing the boundaries with that.

                Can only compare with Apache and Lighty; Apache just seemed to chomp up resource, and for most seems like using a sledgehammer to crack a nut (although mods can be disabled, sure), Lighty seems to drain RAM and from what I have read is poorly maintained .. although maybe that’s changed a bit recently.

                Using a Linode 360, so 360 MB of RAM, and it just hums along.

                Not sure I see the point of strapping Apache to Nginx for fpm, at least for MODx, although I have heard that there can be added performance benefits. When I start breaking some real traffic I’ll be tempted to try.

                In teh meantime, and especially useful to Nginx and/or VPS newbies, I’ve written a copy/paste guide which is linked in my sig. That’s done, but by the time I got to the end I realised there needed to be some help of administering the darn thing, as the one newbie drawback to Nginx is that there is no compatible control panel. Hey, who wants one anyhow! Well, many would, so am currently writing up a 20 part VPS Admin survival guide, covering workarounds for everything that one may want from a panel like cPanel.

                You should get excited about Nginx, Ryan .. it’s just a pain the original docs are in Russian!

                BTW, I feel a Luddite, think I’m running MODx 0.9.7 or something .. love the new site, was pleased to see the link to Nginx, and look forward to finding some time to upgrade to Evolution 1, or 2.
                  www.Guvnr.com

                  .. blogging 'bout a way wider web

                  Currently publishing - a 20 part video series:-

                  Set Up Unmanaged VPS (4 Newbies) .. The V-P-S Bible
                  • 20843
                  • 6 Posts
                  the_guv:

                  I’ve read your guide. It was helpful!

                  I just ended up staying with php-fcgi process, and it’s been working amazing. I only had one problem, due to APC. But it’s been chugging along.

                  Rewrite rules, etc are also much easier. IMO, you don’t really need a control panel, since the configs are so simple to do.

                  And the docs - there’s a wiki and forum now, all in english smiley

                  In terms of control panel, my VPS has ones to create/change DNS entries, all that stuff. I don’t miss cpanel or plex, just editing a config file is much faster for me
                    • 22176
                    • 32 Posts
                    cheers Nabeel .. nice to hear, that was quick smiley

                    For sure, I want to try php-fpm, but you know you don’t need it, nor Apache, to get fastCGI working with Nginx. Then again, I’ve heard that some platforms only work with the php-fpm build but, then again again, with such scarce docs, I wonder if many have tried or bothered to blog their progress.

                    .. would be real interesting to benchmark the two systems on, say, identical slices (you say Slice, I say Linode! .. both darn fine tho, huh.)

                    Yes, the new Nginx wiki is an improvement! Another great resource for tweaking the .conf, adn actually understanding it, is https://calomel.org/nginx.html. To be honest, for someone like you - and I know your site too - that would be more valuable than my guide. there’s a brilliant Apache htaccess > Nginx rewrite rule translater out there too, but can’t find the bookmark.

                    Linode and Slicehost are v similar. It’s the adding vhosts, db backups and whatnot that I’m covering at the moment in the sequel to the VPS Bible, imaginatively titled, er, VPS Admin. Bear in mind that guide’s very much focussed at equipping a newbie with a-z instructions for everything they need.

                    re APC .. don’t suppose you’ve got Zend installed? If so, they don’t sit together. Haven’t tried it (using xCache happily for my purpose) but eAccelerator is supposed to be a good alt. the PHP’s are gonna be including APC in the 6 rollout though, maybe that’ll help.

                    It’ll be interesting to see how this thread develops. To php-fpm or not to php-fpm, when and why? Daresay there’s a few heads about here can put me straight.
                      www.Guvnr.com

                      .. blogging 'bout a way wider web

                      Currently publishing - a 20 part video series:-

                      Set Up Unmanaged VPS (4 Newbies) .. The V-P-S Bible
                      • 28446
                      • 8 Posts
                      Hi folks,

                      I just discovered MODx this week, after getting frustrated with Drupal, for the same reasons posted earlier here:

                      http://modxcms.com/forums/index.php/topic,16101.msg103081.html


                      I use nginx instead of lighttpd. Although the original docs for nginx were in Russian, there is now a very good set of docs in English here:

                      http://wiki.nginx.org/Main


                      The webservers nginx and lighttpd have similar performance:

                      http://superjared.com/entry/benching-lighttpd-vs-nginx-static-files/

                      In the above benchmark, lighttpd is a bit faster.


                      However, I prefer nginx because there are some reports that lighttpd uses more memory, or may have memory leaks:

                      http://drupal.org/node/110224
                      http://www.codeweblog.com/nginx-vs-lighttpd/
                      http://news.ycombinator.com/item?id=527073
                      http://guvnr.com/web/web-dev/install-nginx-not-apache/

                      I do not know if the memory leaks issue has been resolved in later versions of lighttpd.


                      My server (a VPS with 512 megabytes running Debian Etch) uses nginx instead of lighttpd.

                      I set up nginx + PHP + PHP-FPM following the guide here:

                      http://www.yawn.it/2008/04/30/nginx-php-php-fpm-on-debian-etch-40/

                      My PHP (version 5) also uses the xCache PHP accelerator. Other people use other PHP accelerators, such as APC:

                      http://interfacelab.com/nginx-php-fpm-apc-awesome/


                      Yesterday I was able to install MODx (Evolution) in about a half hour, using my existing nginx web server. Everything worked fine.

                      Here is the section for MODx from my ningx.conf file (based on Nabeel’s original post above - thanks!):
                          server {
                              listen 80;
                              server_name .mydomain.net;
                      
                              # index index.php;
                              root   /home/mylogin/sources/modx-1.0.0;
                      
                              location / {
                                index    index.php;
                              }
                      
                              location ~ \.php(/|$) {
                              include fastcgi_params.modx;
                              }
                      
                              # serve static files directly
                              location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico)$ {
                                  root /home/mylogin/sources/modx-1.0.0;
                                  access_log        off;
                                  expires           30d;
                                  break;
                              }
                          }
                      


                      Also, here is the file fastcgi_params.modx referenced in the above code:
                      fastcgi_connect_timeout 60;
                      fastcgi_send_timeout 300;
                      fastcgi_buffers 4 32k;
                      fastcgi_busy_buffers_size 32k;
                      fastcgi_temp_file_write_size 32k;
                      fastcgi_pass 127.0.0.1:9000;
                      fastcgi_index index.php;
                      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                      fastcgi_ignore_client_abort on;
                      fastcgi_intercept_errors on;
                      fastcgi_read_timeout 300;
                      fastcgi_param QUERY_STRING $query_string;
                      fastcgi_param REQUEST_METHOD $request_method;
                      fastcgi_param CONTENT_TYPE $content_type;
                      fastcgi_param CONTENT_LENGTH $content_length;
                      fastcgi_param SCRIPT_NAME $fastcgi_script_name;
                      fastcgi_param REQUEST_URI $request_uri;
                      fastcgi_param DOCUMENT_URI $document_uri;
                      fastcgi_param DOCUMENT_ROOT $document_root;
                      fastcgi_param SERVER_PROTOCOL $server_protocol;
                      fastcgi_param GATEWAY_INTERFACE CGI/1.1;
                      fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
                      fastcgi_param REMOTE_ADDR $remote_addr;
                      fastcgi_param REMOTE_PORT $remote_port;
                      fastcgi_param SERVER_ADDR $server_addr;
                      fastcgi_param SERVER_PORT $server_port;
                      fastcgi_param SERVER_NAME $server_name;
                      fastcgi_param REDIRECT_STATUS 200;
                      


                      My next steps:

                      - Setting up multi-site MODx, perhaps using the following as a guide:
                      http://www.modxcms.de/multiple-domains-with-modx.html

                      - Setting up multi-lingual MODx


                      Setting up mult-site will also require converting the rewrite rules from Apache to nginx, perhaps using the following as a starting point:

                      http://blog.taragana.com/index.php/archive/nginx-hacking-tips/


                      I’m a little nervous about doing this, because I never have converted rewrite rules from Apache to nginx before.

                      Also, I’m new to MODx and PHP, so I hope I will be able to follow the multi-site instructions here:
                      http://guvnr.com/web/web-dev/install-nginx-not-apache/