Wordpress Nginx



  1. Wordpress Nginx Install
  2. Wordpress Nginx Ubuntu 20.04
  3. Wordpress Nginx Docker
  4. Wordpress Nginx Docker
  5. Wordpress Nginx Increase Upload Size
  6. Wordpress Nginx Cache

Topics

  • Generic and Multi-Site Support
  • Better Performance for Static Files in Multisite
  • Resources

Wordpress Nginx Install

While the LAMP stack (Linux + Apache + MySQL + PHP) is very popular for powering WordPress, it is also possible to use Nginx. WordPress supports Nginx, and some large WordPress sites, such as WordPress.com, are powered by Nginx.

When talking about Nginx, it is important to know that there are multiple ways to implement Nginx. It can be setup as a reverse-proxy in front of Apache, which is a very powerful setup that allows you to use all of the features and power of Apache, while benefiting from the speed of Nginx. Most websites that report using Nginx as the server (based on stats gathered from HTTP response headers), are actually Apache running with Nginx as the reverse proxy. (The HTTP response headers showing “Nginx” are being reported by the reverse-proxy, not the server itself.)

2.- Nginx server block for WordPress. Of course, replace “your-domain” with yours. Save the changes and close the file. Next, restart Nginx to enable the new server Block.:$ sudo systemctl restart nginx. So, you need to complete the installation using the web interface. 4.- Install WordPress with Nginx on Ubuntu 20.04. In this final chapter I offer a complete Nginx configuration optimized for WordPress sites. In addition to amalgamating all information from the previous 8 chapters, I will be drawing upon best practices from my experience and various sources I’ve come across over the years. If you're struggling with WordPress rewrite rules on installing it with Nginx inside a subfolder, here's an article which can help. And these commands and you should be set. Undoubtedly, WordPress is one of the most simplest software to install. Sls fluffy fly mask with eyes 2015sugars legacy stables. WordPress even boasts of its famous 5 mins installation. All you have to do is add a.

This guide is referring to a standalone Nginx setup, where it is used as the primary server instead of Apache. It should be noted that Nginx is not a completely interchangeable substitute for Apache. There are a few key differences affecting WordPress implementation that you need to be aware of before you proceed:

  • With Nginx there is no directory-level configuration file like Apache’s .htaccess or IIS’s web.config files. All configuration has to be done at the server level by an administrator, and WordPress cannot modify the configuration, like it can with Apache or IIS.
  • Pretty Permalinks functionality is slightly different when running Nginx.
  • Since Nginx does not have .htaccess-type capability and WordPress cannot automatically modify the server configuration for you, it cannot generate the rewrite rules for you.
  • Without modifications to your install, “index.php” will be added to your Permalinks. (There are ways to mitigate this with plugins (see below) and/or adding custom code to your child theme’s functions.php.)
  • However, if you do want to have some (limited) .htaccess capability, it is technically possible to do add by installing the htscanner PECL extension for PHP. (However, this is not a perfect solution so be sure to test and debug thoroughly before using on a live site.)

This guide is not going to cover how to install and configure Nginx, so this assumes that you have already installed Nginx and have a basic understanding of how to work with and debug it.

Generic and Multi-Site Support Generic and Multi-Site Support

To make WordPress work with Nginx you have to configure the backend php-cgi. The options available are ‘fastcgi’ or ‘php-fpm’. Here, php-fpm is being used because it is included with PHP 5.3+, so installing it is straight forward.

The Nginx configuration has been broken up into five distinct files and is heavily commented to make each option easier to understand. The author also made a best-effort attempting to follow “best practices” for nginx configurations.

Main (generic) startup file Main (generic) startup file

This is equivalent to /etc/nginx/nginx.conf (or /etc/nginx/conf/nginx.conf if you’re using Arch Linux).

This is a bit different from standard nginx.conf files. This configuration follows the Ubuntu/Debian method of declaring enabled sites for maximum flexibility – using ‘sites-available’ to store a config and then symlink to the config file from ‘sites-enabled’.

Per Site configuration Per Site configuration

Splitting sections of the configuration into multiple files allows the same logic to be reused over and over. A ‘global’ subdirectory is used to add extra rules for general purpose use (either /etc/nginx/conf/global/ or /etc/nginx/global/ depending on how your nginx install is set up).

Global restrictions file Global restrictions file

General WordPress rules General WordPress rules

For single site installations, here is the ‘global/wordpress.conf’ file:

This is more up-to-date example for Nginx: https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/

WordPress Multisite Subdirectory rules WordPress Multisite Subdirectory rules

For multisite subdirectory installations, here is the ‘global/wordpress.conf’ file:

NGINX provides 2 special directive: X-Accel-Redirect and map. Using these 2 directives, one can eliminate performance hit for static-file serving on WordPress multisite network.

WordPress Multisite subdomains rules WordPress Multisite subdomains rules

Ref: https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/

HTTPS in Nginx HTTPS in Nginx

Enabling HTTPS in Nginx is relatively simple.

Mozilla offers an excellent SSL config generation tool as well.

WP Super Cache Rules WP Super Cache Rules

Experimental modifications:

If you are using HTTPS, the latest development version of WP Super Cache may use a different directory structure to differentiate between HTTP and HTTPS. try_files line may look like below:

W3 Total Cache Rules W3 Total Cache Rules

W3 Total Cache uses different directory structure for disk-based cache storage depending on WordPress configuration.

Cache validation checks will remain common as shown below:

FOR Normal WordPress (without Multisite)
Use following:

FOR Multisite with subdirectories
Use the following:

FOR Multisite with Subdomains/Domain-mapping
Use following:

Wordpress Nginx

Notes

  • Nginx can handle gzip & browser cache automatically so better leave that part to nginx.
  • W3 Total Cache Minify rules will work with above config without any issues.

Nginx fastcgi_cache Nginx fastcgi_cache

Nginx can perform caching on its own end to reduce load on your server. When you want to use Nginx’s built-in fastcgi_cache, you better compile nginx with fastcgi_cache_purge module. It will help nginx purge cache for a page when it gets edited. On the WordPress side, you need to install a plugin like Nginx Helper to utilize fastcgi_cache_purge feature.

Config will look like below:

Define a Nginx cache zone in http{…} block, outside server{…} block

For WordPress site config, in server{.} block add a cache check block as follow

Then make changes to PHP handling block

Just add this to the following php block. Note the line fastcgi_cache_valid 200 60m; which tells nginx only to cache 200 responses(normal pages), which means that redirects are not cached. This is important for multilanguage sites where, if not implemented, nginx would cache the main url in one language instead of redirecting users to their respective content according to their language.

Such that it becomes something like this

Finally add a location for conditional purge

If you get an ‘unknown directive “fastcgi_cache_purge”‘ error check that your Nginx installation has fastcgi_cache_purge module.

Better Performance for Static Files in Multisite Better Performance for Static Files in Multisite

By default, on a Multisite setup, a static file request brings php into picture i.e. ms-files.php file. You can get much better performance using Nginx Map{.} directive.

In Nginx config for your site, above server{.} block, add a section as follows:

It is just a list of site-names and blog-ids. You can use Nginx helper to get such a list of site-name/blog-id pairs. This plugin will also generate a map.conf file which you can directly include in the map{} section like this:

After creating a map{.} section, you just need to make one more change in your Nginx config so requests for /files/ will be first processed using nginx map{.}:

Notes Notes

  • Whenever a new site is created, deleted or an extra domain is mapped to an existing site, Nginx helper will update map.conf file automatically but you will still need to reload Nginx config manually. You can do that anytime later. Till then, only files for new sites will be served using php-fpm.
  • This method does not generate any symbolic links. So, there will be no issues with accidental deletes or backup scripts that follow symbolic links.
  • For large networks, this will scale-up nicely as there will be a single map.conf file.

Notes Notes

A couple of final but important notes: This whole setup assumes that the root of the site is the blog and that all files that will be referenced reside on the host. If you put the blog in a subdirectory such as /blog, then the rules will have to be modified. Perhaps someone can take these rules and make it possible to, for instance, use a:

directive in the main ‘server’ block and have it automagically apply to the generic WP rules.

Warning Warning

  • A typo in Global restrictions file can create loopholes. To test if your “uploads” directory is really protected, create a PHP file with some content (example: <?php phpinfo(); ?>), upload it to “uploads” directory (or one of its sub-directories), then try to access (execute) it from your browser.

Resources Resources

Wordpress Nginx

Reference Reference

  • nginx + php-fpm + PHP APC + WordPress multisite (subdirectory) + WP Super Cache (Thanks bigsite)
  • Notes on removing ‘index.php’ from Permalinks (Can be done using Nginx Helper Plugin)

External Links External Links

Scripts & Tools Scripts & Tools

  • For WordPress Nginx scripted installation CentminMod can be used for CentOS.

Securing Nginx Securing Nginx

ⓘ This article may have been partially or fully translated using automatic tools. We apologize for any errors this may cause.

Today we will talk to you about wordpress, the most popular CMS in the world (not to mention the fact that it runs Raspbian France) and see how to install it on the Raspberry Pi.
The Raspberry / WordPress compatibility exists since the beginning, nevertheless, the performances on the first Raspberry Pi were not incredible!
Today, with the Raspberry pi 3 and the Raspberry Pi 2, it’s ancient history! Their processors and the RAM mounted at 1GB offers us the possibility to run more than correct way a wordpress site under Raspbian!

Install the server on your Raspberry Pi

Besides the classic commands of updates that should be executed before any installation, we will have to install a web server as well as PHP and MySQL on the Raspberry Pi.

Here we choose to install Nginx. Indeed, if it is a little more complicated to configure than Apache, it is also significantly faster, which will be a real advantage on a Raspberry Pi. Wondershare edrawmax for mac.

With this command, all necessary repositories will be installed, namely Ngnix, PHP and finally MySQL which is the database used by WordPress.

During the installation, you will be asked for some information, in particular the name and the password of the MySQL account, memorize well the information given, they will be useful thereafter!

Once the installation is complete, you will need to configure Nginx. To do this, see the “Configure Nginx” section of our Install Nginx Raspbian tutorial, and accelerate your Raspberry web server.

Creating a database for WordPress on the Raspberry Pi

Following this installation we will have to create a database for the future WordPress site hosted on the Raspberry Pi.

Let us explain this command quickly. “sudo” allow us to execute the command as administrator when “mysql” requests a connection to the database server, “-u” is used to report the name of the MySQL account to use (here the root account).

Now, we will define the password to use for MySQL. Once connected to MySQL, run the following commands :

Those commands will delete the default MySQL user (who have no password) and create a new account whith the password of our choice. For that, replace password by the password you want to use for MySQL.

Création de la base pour WordPress

Once this is done, you will be connected to MySQL (you should see at the beginning of the line “mysql>”) with the following command :

Now, we will create a database for WordPress. To do this, use the following command:

Proxy

Here, “wordpress” is the name of the database that will be used, you can put another name if you wish, but you will have to consider this difference in the continuation of the tutorial.

Creating a dedicated user for this database

A good habit to take when using a database is to separate the different tables between several dedicated users.
This increases safety! Indeed, if a person succeeds in taking control of your site because of a security breach (it can always happen), two situations are possible.

  1. You use a single MySQL user, root, with all rights to all tables. The attacker will thus be able to recover not only the data of the attacked site, but also the data of all the other sites.
  2. You use a MySQL user per site that owns rights only on the basis of this site. The attacker will be able to recover only the data of this site!

Here, we will create a dedicated user for your WordPress site.
To do this, simply run the following command:

In this command, “wordpress” is the name of the database, “username” the name of the user you want to create and “password” the user’s password! So you adapt according to your preferences!

You can now quit MySQL with Ctrl + d.

Download WordPress on Raspberry Pi

Now that our database is ready and our Nginx server is installed, we will be able to download WordPress!
First, we will go to the root of the server, which is, if you followed our tutorial on Ngnix, located in /var/www/html, then we will download the latest version of WordPress. To do this, run the following command lines:

Then we will extract the content via the command “tar”.

A new folder will be created during the extraction, the “wordpress” folder. We have removed the archive, which is now useless.

We will ensure that Nginx has access to the file. To do this, run the following command:

Wordpress nginx reverse proxy config

Wordpress Nginx Ubuntu 20.04

Configure Nginx to redirect queries to WordPress

Wordpress Nginx Docker

Wordpress Nginx

For your site to be accessible from the internet with the URL of your choice, and for the requests to be all processed by WordPress, you will have to modify somewhat the configuration of Nginx.

To do this, we will start by writing the file “/etc/nginx /sites-available /wordpress”. This file should contain the following code:

Of course, replace <your_site_name> with the appropriate values. If you do not have a domain name, you can replace it with the IP address of your Raspberry Pi for the “server_name” field.

Once the file is saved, you will make a symbolic link to activate the setting. To do this, simply use the following command line:

All you have to do now is restart the Nginx server with the following command:

First connection to WordPress on your Raspberry Pi

We will now connect to the WordPress for the first time to finalize the installation.
In the browser, we will type the ip of the Raspberry Pi (you can find the IP in the configuration of your box).
In our case for example, this gives http://192.168.1.24
You should then arrive on the next page.

Wordpress Nginx Docker

When you first start WordPress you will find yourself on the installation page

You just have to follow the steps one after the other in order to complete the installation of WordPress on the Raspberry Pi.

Conclusion

Wordpress Nginx Increase Upload Size

You now have a great WordPress site on your Raspberry Pi which is accessible locally!
All you need to do is check out our tutorial on fowarding port and dydns, to see how to make it accessible from the internet!
The performance of the Raspberry Pi 3 should greatly improve those of the site compared to previous versions, and for a healthy Raspberry Pi, go on our article about the choices of accessories!

Wordpress Nginx Cache

3/5(2 votes )




Comments are closed.