• 21

Configure WordPress with NGINX

NGINX WordPress Setup

In this post, I will show you how to setup WordPress blog with NGINX. I was using WordPress with Apache2 server but I decided recently to use NGINX.


  • Working LEMP server (Linux, Nginx, Mysql and PHP)
  • Root access to the server
  • WordPress configuration file and sql
  • DB already imported to the mysql


In this example, our database info is follow :

  • db : wptest
  • pass: passWpTest
  • user : wptest
  • host : localhost


First, we need to download the latest version of WordPress and put in desired folder.

After that, rename the wp-config-sample to wp-config.php. You can make a copy in case you need an original file.

Open the wp-config.php with your editor of choice and change the following configuration :

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wptest');

/** MySQL database username */
define('DB_USER', 'wptest');

/** MySQL database password */
define('DB_PASSWORD', 'passWpTest');

/** MySQL hostname */
define('DB_HOST', 'localhost');

After that, we need to create a virtual host in nginx folder to be able to configure WordPress via browser.

You create a new file on the folder  with name of the website you want.


I created a file called wptest.itsecurenet.com.conf


Once the file is created  and add the following content for basic website. The following code was used from WordPress.org website : https://codex.wordpress.org/Nginx

# WordPress single site rules.
# Designed to be included in any server {} block.
# Upstream to abstract backend connection(s) for php
upstream php {
        server unix:/tmp/php-cgi.socket;

server {
        ## Your website name goes here.
        server_name wordpressnginx.itsecurenet.com;
        ## Your only path reference.
        root /var/www/html/wptest;
        ## This should be in your http block and if it is, it's not needed here.
        index index.php;

        location = /favicon.ico {
                log_not_found off;
                access_log off;

        location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;

        location / {
                # This is cool because no php is touched for static content.
                # include the "?$args" part so non-default permalinks doesn't break when using query string
                try_files $uri $uri/ /index.php?$args;

        location ~ .php$ {
                #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
                include fastcgi.conf;
                fastcgi_intercept_errors on;
                fastcgi_pass php;

        location ~* .(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                log_not_found off;


Two main thing that you have to change is the server name and the website root folder location.

Once the file is changed and saved, we need to activate the website by creating symbolic link. We need to make a link to another folder which is :


So, type the following command but by changing the correct filename that you just created. For me, it will be like this :

ln -s /etc/nginx/sites-available/wordpressnginx.itsecurenet.com.conf /etc/nginx/sites-enabled/

You can check the nginx configuration is correct before restarting the service by typing the following command :

nginx -t

If you do not get any errors, now you can reload nginx service by typing the command :

service nginx reload

You might also restart the php5-fpm service if needed :

service php5-fpm restart

Also, make sure that the permission are correctly set to WordPress folder website. We need to make sure that www-data is part of the group for that folder. For example, my WordPress root installation folder is located at /var/ww/html/wptest. So, we typed the following command :

chown -R www-data:www-data/var/ww/html/wptest/

Once that is done, you can visit your website from browser of your choice to finalize the installation. In my case, it will be wordpressnginx.itsecurenet.com


The post Configure WordPress with NGINX appeared first on IT Secure Net.

Powered by WPeMatico

Comments are closed.


Choose a combination of predefined colors here. Here are some examples. You can create any additional number on your backend theme, also can choose the background you want and four differents layouts.