What issues would you face if you use Nginx

WordPress is quite a memory hog, and I’ve been thinking of using nginx rather than apache.

The one major consideration before doing that is if there are any plugins which will stop working. I have tested a few and they seem to work, but I need to find out if there are any which might break.

Related posts

Leave a Reply

7 comments

  1. I unfortnately have no experience with this but evidently it can be done as these articles and plugins address some of the issues:

    Also are you familiar with WP Engine WordPress hosting? They are evidently using it in a hybrid form with Apache, probably as a front-end proxy.

    Hope these help.

  2. Small world :). You won’t see a lot of issues with Nginx and Apache + WordPress. We use it for our company as well, and we have no problem getting one server to serve 200k uniques/month and over a million pageviews/month for one site. Nginx + W3 Total Cache, you get some very remarkable numbers.

  3. The biggest difference is rewrite rules, but there are plenty of guides out there (such as the ones Mike linked) that provide you with equivalent rewrite rules.

    From a plugin perspective, unless the plugin is doing something really crazy, then it shouldn’t know the difference. All internal rewrite rules and that sorta stuff is handled at the WordPress level, independently of your HTTPD.

    In short, go for it.

  4. Using Nginx will not make WordPress use less memory. If you’re concerned about memory, you can save some server-wise by optimizing your Apache configuration to only load the modules you need and do other configuration that will reduce the memory apache needs.

    Next to that, Apache has caching modules as well worth to consider, so to save all memory WordPress would have used when invoked. Since WordPress output get’s cached, WordPress does not need to run any longer and you save the memory.

  5. When WordPress detects that mod_rewrite is not loaded it falls back to pathinfo ie:(/index.php/%postname%/) permalinks in Permalink Settings page. You can use the nginx Compatibilityplugin to force WordPress to use pretty permalinks then add rewrite rules to your nginx server file:

    server { server_name mysite.com;
    
    root /path/to/blog;
    
    index index.php;
    
    location / {
        try_files $uri $uri/ @wordpress;
    }
    
    location @wordpress {
        fastcgi_pass ...;
        fastcgi_param SCRIPT_FILENAME $document_root/index.php;
        include /etc/nginx/fastcgi_params;
        fastcgi_param SCRIPT_NAME /index.php;
    }
    
    location ~ .php$ {
        try_files $uri @wordpress;
        fastcgi_index index.php;
        fastcgi_pass ...;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include /etc/nginx/fastcgi_params;
    }
    
    }
    
  6. The docs are written in Russian and somewhat vague. Sometimes you’re wondering if the translation is bad or if the docs are just not very explicit in the first place. So finding answers is sometimes time-consuming and/or requires trial-and-error testing.

    However, the author seems very engaged with the community, explaining configuration options. And NginX itself gives you some feedback, such as “you can’t use this option here.”

  7. I have done research for Ngnix, varnish caching enabled wordpress setup.

    Nginx Virtualhost configuration for wordpress.

    server {
            listen 127.0.0.1:8080 default_server;
            listen [::]:8080 default_server;
             root /var/www/html/wordpress;
            index index.php index.html index.htm;
            server_name yourdomain.com www.yourdomain.com;
            location / {
                            try_files $uri $uri/ /index.php?$args;
                    }
             location ~ .php$ {
                                    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
                                    fastcgi_index index.php;
                                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                                    fastcgi_param PATH_INFO $fastcgi_path_info;
                                    include fastcgi_params;
                                }
    }
    

    Install varnish open file /etc/default/varnish, configure like below.

    DAEMON_OPTS="-a :80 
                 -T localhost:6082 
                 -f /etc/varnish/default.vcl 
                 -S /etc/varnish/secret 
                 -s malloc,256m"
    

    Check the running port.

    netstat -ntulp
    

    if netstat command not found.

    sudo apt-get install -y net-tools