Setting Web Server Nginx WordPress

Setting Web Server Nginx WordPress


WordPress is one of the most popular content management systems (CMS) and blogging platforms, and Nginx is becoming more and more popular as a web server – even overtaking Apache for certain applications. This guide will show you how to install Nginx on Ubuntu 14.04 and configure it to serve a WordPress website.

Installing Nginx on Ubuntu 14.04

Nginx is included in the standard Ubuntu 14.04 repositories. You can install it by running the following command:

sudo apt-get update
sudo apt-get install nginx

Once the installation is complete, you can start the Nginx service and make sure that it is automatically started on boot with the following commands:

sudo service nginx start
sudo update-rc.d nginx defaults

At this point, Nginx is installed, and running on your system.

Configuring Nginx for WordPress

Once Nginx is installed, it is time to configure it for WordPress. First, you need to create a virtual host configuration file for your domain name. You can do this by creating a new file in the ‘/etc/nginx/sites-available/‘ directory:

sudo nano /etc/nginx/sites-available/

In this file, add the following configuration. Be sure to replace the example values with your own domain name, and the location you want to serve the WordPress files from:

server {
listen 80;


root /var/www/wordpress;
index index.php index.html;

location / {
try_files $uri $uri/ /index.php?$args;

location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;

Once you have saved the file, you need to enable the virtual host. You can do this by creating a symbolic link from this file to the ‘/etc/nginx/sites-enabled/‘ directory:

sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

Finally, you need to test the configuration for any syntax errors:

sudo nginx -t

If your configuration contains any syntax errors, the output from this command will be detailed. You can edit your configuration file and repeat the test command until the configuration file is error-free.

Once you have a valid configuration, you can restart Nginx for the changes to take effect:

sudo service nginx restart

Nginx is now ready to serve a WordPress website.

Installing WordPress

You can install WordPress by following the official WordPress installation guide.

To start, you can download the latest version of WordPress to your server:


Once the download is complete, you can extract the archive with the following command:

tar -xzvf latest.tar.gz

This will extract the WordPress files to your current directory. Move them to the ‘/var/www/wordpress/’ directory, which is specified in your Nginx configuration file.

sudo mv wordpress/* /var/www/wordpress

At this point, you can access the WordPress installation script in your web browser by visiting your domain name or IP address. Follow the on-screen instructions to complete the WordPress installation.

Configuring Nginx for Permalinks

WordPress Permalinks depend on URL rewriting, which is handled by the Nginx configuration file. By default, Nginx does not have any rewrite rules specified. You need to modify your virtual host configuration to include the following code, which will rewrite the URL’s correctly for WordPress Permalinks:

location / {
try_files $uri $uri/ /index.php?args;
rewrite ^/wp-admin$ $scheme://$host$uri/ permanent;
rewrite ^(/[^/]+)?(/wp-.*) $2 last;
rewrite ^(/[^/]+)?(/.*.php) $2 last;

Once you have added this code, you can restart Nginx for the changes to take effect:

sudo service nginx restart

Your WordPress Permalinks should now be working correctly.


By following this tutorial, you have now installed Nginx on your Ubuntu 14.04 server and configured it to serve a WordPress website. With a few simple commands, you can have a web server up and running in no time.


Q: What is Nginx?

A: Nginx is a web server software commonly used to serve web applications and static content. It is highly regarded for its performance and scalability.

Q: What version of Ubuntu is required to install Nginx?

A: Nginx is available in the official repositories of Ubuntu 14.04, and can be installed by running sudo apt-get install nginx.

Q: How do I enable URL rewriting for WordPress Permalinks?

A: By adding a rewrite rule to the Nginx configuration file, URL rewriting can be enabled for WordPress Permalinks. See the Configuring Nginx for Permalinks section of this article for more details.

Thank you for reading this article. Please read other articles about web development and web servers.

Leave a Reply

Your email address will not be published. Required fields are marked *