Archive

How to Switch from Apache to Nginx

In our recent series of posts, we have explained a lot of things about Linux web servers. The three main Linux web servers that we introduced were Nginx, Apache, and Lite Speed. We said some pros and cons for each of them. We also mentioned that Apache is the most commonly used web server all over the world. For any reason, you may choose a web server and then decide to change it later. In this post, we are going to show you how you can switch your web server from Apache to Nginx.

Switch from Apache to Nginx Web Server

The first thing you need to do is establishing an SSH connection to your server using Softwares like PuTTY. You need to have root access to your server. So, if your service is anything that doesn’t give you the root access, you need to ask your hosting provider to switch the webserver for you.

After logging into the server using PuTTY, you need to check the version of your control panel‘s “Custombuild”. Use the commands below to check and upgrade.

Check the Version:

 cd /usr/local/directadmin/custombuild
./build version 

Upgrade the Version:

 cd /usr/local/directadmin
mv custombuild custombuild_1.x
wget -O custombuild.tar.gz http://files.directadmin.com/services/custombuild/2.0/custombuild.tar.gz
tar xvzf custombuild.tar.gz
cd custombuild
./build 

Now we can simply use this command to switch from Apache to Nginx:

 cd /usr/local/directadmin
./build set webserver nginx 

This is what you are going to see at the end of the process:

After this, you need to change the PHP handler. We’ve already explained that every webserver has its own ph handler. Apache supports almost all of PH handles. So here we need to change the PHP handler to PHP-FPM.

 /build set php1_mode php-fpm

Now copy and paste these commands in turn:

 ./build update 
 ./build all d 

*This Process may take more or less than 20 minutes depending on the server’s RAM.*

Build Update

Let’s finish the installation:

 ./build rewrite_confs 
Nginx installation

As the last step, restart Nginx to finish the process:

 /sbin/service nginx restart 

You have successfully switched your webserver from Apache to Nginx!

Hope you enjoyed this post if you did, you can visit our blog for more!

Setup Nginx Server Block (Part 2)

In our last post, we explained that if you want to handle more than one domain using Nginx, you need to set up the Nginx Server block. We also explained half of the steps so if you haven’t checked that out yet, here is the link:

We completed setting up the Nginx server block for the first domain so let’s go and setup the second server block.

Setup the second Nginx server block

We need to do the exact same thing for the second domain. There is only going to be one difference through this process and it’s that we need to remove default_server from the listen directory in config file. This is because we can only have one default_server or else the webserver won’t work.

There is a default server block in this path:

/etc/nginx/sites-available/default

Now we copy the file with a new name based on the domain:

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/mytest2.com

Then we need to edit the file:

sudo nano /etc/nginx/sites-available/mytest2.com

Scroll the file to find the “listen” section:

Edit file

Remove default_server from the “listen” section:

Find the root /var/www/html in the mentioned file and replace it with the path of the directory you made earlier. For example /var/www/mytest2.com/public_html.

Now find the server_name _;  line and change the domain name. (You can search for this line using Ctrl+W)

Save the changes and close the file. (Use Ctrl+X then Y to save changes)

Just like the other one let’s make sure the Nginx config file exists:

sudo nginx -t

You should see this as a result:

You are done setting up the second Nginx server block.

Creating a Symbolic Link

Now we are going to create a symbolic link from sites-available in the sites-enabled directory. This will technically call the Nginx web server.

sudo ln -s /etc/nginx/sites-available/mytest1.com /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/mytest2.com /etc/nginx/sites-enabled/

Remove the symbolic link from the default server:

sudo rm /etc/nginx/sites-enabled/default

Restart Nginx:

sudo service nginx restart

Test

Assuming that you have already done all the DNS configurations on the Domain side and it’s pointing to the Server‘s IP, you can see the test page on your browser.

Nginx Test Page

Hope you enjoyed this post if you did, you can visit our blog for more!

Setup Nginx Server Blocks (Part 1)

Based on our previous posts, now you know a lot about web servers and especially about Linux web servers. We’ve explained about LiteSpeed, Apache, and Nginx Web Server and compared them. We said it multiple times that although Nginx doesn’t have a GUI but it’s amazing for handling more than one domain. To handle multiple domains, first you need to setup server blocks. In this post, we’re going to show you how you can do that.

So, installing Nginx and configuring its firewall, you need to setup server blocks. We think that even if you want to handle one domain with this, it’s a good idea to setup the server block to make adding other domains easier in the future.

Making Directories

In this post, we are going to use these two to setup server blocks and make new directories:

  • mytest1.com
  • mytest2.com

The first step is to create two directories for two domains:

sudo mkdir -p /var/www/mytest1.com/public_html
sudo mkdir -p /var/www/mytest2.com/public_html

If you want the files to be editable by users other than the root, use these commands:

sudo chown -R $(whoami):$(whoami) /var/www/mytest1.com/public_html
sudo chown -R $(whoami):$(whoami) /var/www/mytest2.com/public_html

Create a text page

let’s create an index.html page for each domain:

sudo echo "Welcome to mytest1.com!" > /var/www/mytest1.com/public_html/index.html
sudo echo "Welcome to mytest2.com!" > /var/www/mytest2.com/public_html/index.html

Setup the first server block

There is a default server block in this path:

/etc/nginx/sites-available/default

Now we copy the file with a new name based on the domain:

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/mytest1.com

Then we need to edit the file:

sudo nano /etc/nginx/sites-available/mytest1.com

Find the root /var/www/html in the mentioned file and replace it with the path of the directory you made earlier. For example: /var/www/mytest1.com/public_html

Edit file

Now find the server_name _;  line and change the domain name. (You can search for this line using Ctrl+W)

Save the changes and close the file. (Use Ctrl+X then Y to save changes)

Before going for the next step, let’s make sure the Nginx config file exists:

sudo nginx -t

You should see this as a result:

The first server block has been set up and in our next post, we’ll show you how to set up the second one. Make sure to check that post to finish the setup of the server blocks.

Hope you enjoyed this post if you did, you can visit our blog for more!

Nginx Installation and Firewall Configuration

In this post, we’ll explain the installation for the latest version of Nginx and its firewall configuration.

Nginx is one of Linux web servers which has lots of pros and cons. One thing about Nginx is that it doesn’t have a panel on control panels like other web servers. So this makes things a bit harder but still manageable. In our last post, we explained how you can install SSL with having Nginx as your web server.

Nginx Web Server

Nginx Installation

Connect to your server using an SSH connection. Now use the command below to download and install the latest version of Nginx on your server.

sudo apt update && sudo apt install nginx
sudo apt install -y nginx

After the installation, you can check the installed version using this command:

nginx -v

Then you need to check the web server’s status as we want it to be up and running:

sudo service nginx status

The Nginx installation is complete and now you need to configure the firewall.

Firewall Configurations

After the installation, we recommend you to enable ufw so you’ll be able to add rules on Nginx. (Before doing that, check your SSh access so you won’t get blocked.)

sudo ufw allow OpenSSH

Now let’s add rules on Nginx:

sudo ufw allow 'Nginx HTTP'

You should see this:

Rule added
Rule added (v6)

Enabling ufw in Firewall:

sudo ufw enable

Now let’s check the Firewall’s status:

sudo ufw status

You should see this:

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
Nginx HTTP                 ALLOW       Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)
Nginx HTTP (v6)            ALLOW       Anywhere (v6)

Nginx installation is done and it’s up and running now!

In our next post, we are going to show you how you can handle more than one domain with Nginx web server.

Hope you eno=joyed this post if you did, you can visit our blog for more!

Installing SSL Certificate on Nginx

In our last post, we compared Nginx and LiteSpeed. These two are two popular Linux web servers. One of the things that we mentioned about Nginx was that it can’t be controlled by control panels like other web servers. Both Apache and LiteSpeed have their panels on DirectAdmin, cPanel and etc. Obviously, it’s much easier to install SSL using control panels like DA, cPanel, Plesk, CyberPanel, and etc but in this post, we’re going to show you how you can install SSL on Nginx.

Before installing SSL you need to finish ordering an SSL certificate and get the needed files from the provider. The files that you’re gonna need are:

  • The certificate file
  • Private key
  • CSR
  • Ca

*To get the private key, you can use online CSR Generators*. So just go to CSRgenerator.com and fill in the forms to get your CSR and private key so you can install SSL.

Installing SSL on Nginx

1. Login to the server using an SSH connection.

2. Go to the address below and create a .key and a .crt file.

etc/Nginx/SSL

So you’re going to create two files like your-domain-name.crt and your-domain-name.key using the touch command. Now copy what’s in the Private key file and paste it in the .key file. Then copy what’s in the certificate and ca file and paste it in the .crt file. Save your changes and go for the next step.

3. Now you need to edit the Nginx configuration file. To do that, go to nginx.conf and add this to the Nginx configuration file:

server {listen   ۴۴۳; ssl    on; ssl_certificate    /etc/ssl/your_domain_name.crt; ssl_certificate_key    /etc/ssl/your_domain_name.key;

Also, go to the Nginx virtual hosts file from the path below and add the same lines to it:

/etc/nginx/sites-available/yourdomain

The installation is complete and your SSL is ready to use.

Hope you enjoyed this post if you did, you can visit our blog for more!

Nginx vs LiteSpeed Web Server

In our post about different Linux web servers, we talked about Apache, Nginx, and LiteSpeed. In this post, we are going to compare the Nginx and LiteSpeed Web server specifically.

Both of these web servers have free and premium versions. So there is not much of a difference in their cost. Mostly, LiteSpeed is compared with Apache but it has lots of similarities with Nginx so this comparison is much more useful.

LiteSpeed vs Nginx

LiteSpeed can read all the Apache files like mod_rewrite, mod_security but Nginx can’t do the same. Also one of the biggest weak points of Nginx is that it can’t read .htacess file.

LiteSpeed web server and Apache can be controlled by control panels like DirectAdmin, cPanel and Plesk. But Nginx isn’t like that.

Now let’s say some of the good features of Nginx. The best thing about Nginx is that it can handle a high number of visits. So this is a very popular web server for websites with lots of views.

Fortunately, both Nginx and LiteSpeed use ModSecurity rules and protect server from multiple attacks. So they have a similar function in the security subjects.

There are lots of other amazing features about Nginx which we talked about them in the post about Nginx before.

In the end, we can’t obviously tell you which web server is the best for everyone. Each website has its own needs and you need to carefully compare and consider each web server’s features and choose the one that matches your needs the best. One thing we can suggest is that if you are starting a website, Apache is most probably the best option for you. You can always switch to LiteSpeed web server later. However, switching from Apache to Nginx is a bit tricky and hard.

Hope you enjoyed this post if you did, you can visit our blog for more!

Nginx Web Server

Previously, we’ve talked about what a web server is and what different Linux web servers are. We also explained about Apache which is the most commonly used Linux web server in the world. In this post, we are going to talk about Nginx which is another Linux web server.

What is Nginx?

Nginx is a very successful open-source web server that is also used as a reverse proxy, load balancer, and HTTP cache. From the start, it worked on high performance and optimized RAM usage. This web server is compatible with lots of operating systems like OS X, Linux, HP-UX, Solaris and etc.

Nginx best Features

Here are some of it’s best features:

  • It can support and manage more than 10000 simultaneous connections with low RAM usage.
  • Load Balancing
  • Fault tolerance
  • Supports SPDY protocol
  • The ability to compress and extract gzip files
  • Supports STARTTL
  • and etc…

There are also some cons about this web server which are:

  • It doesn’t offer us an easy GUI to use. But it has a built-in dashboard that allows you to control things by it. 
  • It doesn’t support .htaccess file.

Nginx Installation on WHM

This web server has a very easy installation. All you have to do is to connect to your server using an SSH connection and then copy and paste these commands in turn:

cd /usr/local/src
wget http://nginxcp.com/latest/nginxadmin.tar
tar xf nginxadmin.tar 
cd publicnginx
./nginxinstaller install

After the installation you can go to the Plugins section of WHM, to see the Nginx plugin that you have just installed.

So from now on, the Nginx will replace Apache in your server and will be used by all websites.

Uninstall Nginx from WHM

You can use those simple commands above for installation but replace “Install” with “uninstall” in the last line.

cd /usr/local/src
wget http://nginxcp.com/latest/nginxadmin.tar 
tar xf nginxadmin.tar
cd publicnginx
./nginxinstaller uninstall

We hope that you enjoyed this post. If you did, you can check our blog for more!

Apache Web Server

Apache HTTP Server is one of the famous Linux web servers. It is the most commonly used web server all over the world. They created this web server based on NCSA HTTPd and had a major role in world wide web’s growth. After overtaking the NCSA HTTPd, Apache became the most popular web server for HTTP from 1996. In 2009, it became the first web server software in the world by supporting more than 100 million websites. This Web Server is a free and open-source webserver that works the best on Unix and Linux servers. However, it is also accessible on Microsoft, OS X, Solaris Novell NetWare, FreeBSD, EComStation, OpenVMS, TPF, Windows and etc.

Why They named it Apache?

At first they said the name ‘Apache’ was chosen from respect for the Native American Indian tribe of Apache (Indé), well-known for their superior skills in warfare strategy and their inexhaustible endurance. But the reason on their FAQ page changed to this: A cute name which stuck. Apache is “A Patchy server”. It was based on some existing code and a series of “patch files”. And now it means much more than that. It is the first and foremost the Apache Software Foundation, under which there are dozens of projects.

As we mentioned in the post about Linux web servers, Nowadays Apache is the default web server for most control panels. It is a modular web server which makes it very flexible and easy to use. It pretty much has a module for anything you want along with a good GUI. We should also say that you can choose any PHP handler you want with this web server. It can work perfectly for you if you want to handle multiple websites on your server.

Hope you enjoyed this post if you did, you can visit our blog for more!

Comparing Different Linux Web Servers

Earlier in our posts, we have explained what a Web Server is. In the same post, it is mentioned that there are different Web Servers that some work on Windows servers and some work on Linux Servers. Here we are going to compare different Linux Web Servers.

Apache-vs-Nginx-vs-Litespeed

Nginx, Apache and LiteSpeed are the three famous Linux Web Servers. Nginx and Apache are both free and open source. Between these two, Apache is more popular and it’s the default web server for most control panels. Apache is a modular web server which makes it very flexible and easy to use. It pretty much has a module for anything you want along with a good GUI. On the other hand, Nginx doesn’t offer us an easy GUI to use. Nginx has a built-in dashboard that allows you to control things by it. Another thing about Nginx is that it doesn’t support .htaccess file which makes it really risky for us to switch between Apache and Nginx.

LiteSpeed is much faster and more optimized than the other two but it comes with a cost. You need to buy a license to use this web server. If you have a website with lots of viewers and data this can help you speed up your websites functionality a lot. However, this doesn’t mean that if your website is slow because of its codes you can solve the problem with Litespeed! You can make it faster but it’s better to take care of your codes and then use Litespeed if needed. Just like Apache, Litespeed also has a great GUI to work with.

Which Linux Web Server is more secured?

Security has so many layers and you take care of all those layers to make your server safe. But if we only want to answer this question about the web servers, we should say that since Apache and Nginx are open source, their security holes can be found and fixed sooner and easier.

Every web server uses a different PHP handler that each have their own features. Litespeed uses its own PHP handler which is LSPHP and Nginx uses php-fpm. On the other hand, Apache supports all PHP handlers like SUPHP, CGI and etc except LSPHP that is for Litespeed. CGI is faster than SUPHP but if you permissions for SUPHP it can be more secured.

Which Web Server do we recommend?

We surly can’t decide which Linux web server works for you the best. What we can say is that Nginx is designed for special usages. This means that because of Nginx’s features, it works perfectly if you have one website with lots and lots of audiences. But for multiple websites it might be easier to use Litespeed and Apache because of their GUI. However this is just a suggestion and the results may differ according to your websites and usages.

Hope you enjoyed this post if you did, you can visit our blog for more!

Windows Host vs. Linux Host

Previously, we have explained fully about what a server is, different servers in web hosting and other related things like the control panels, SSL and etc. In the posts about different control panels, we kept talking about Linux or Windows hosts. In this post, we are going to talk about the differences between Linux host and Windows host.

Linux host vs. Windows Host

Windows Servers

As you know, the first step of having a successful website is having a good domain. We will explain how you can choose a good domain, in a future post.

After choosing a domain, now you need to choose your hosting service. If you have a website for personal use or for a small business, this means you don’t need that much space and resources. So, shared hosting can be a perfect solution for you. The first things you’ll see at the time of buying a shared hosting plan are: Linux host, Windows host, cPanel, Plesk, DirectAdmin, and etc. As we’ve mentioned before, some control panels work on Linux, some work on Windows and some work on both.

  • cPanel, Plesk, DirectAdmin,..: These are hosting control panels that we’ve explained each of them fully before.

Choosing the control panel depends on what OS has been installed on the server. So, if you need a specific control panel, you need to buy a hosting plan that can support the control panel for you. For example, if you specifically want cPanel as your control panel, you need to buy a Linux server because cPanel only works on Linux. We should mention that the OS that we install on servers are not the same as the ones you install on PC. There are special distributions of Linux and Windows just to be installed on servers. Another thing to mention is that there are other operating systems that you can install on servers but Linux and Windows are the most common and professional ones.

Linux Servers or Windows Servers?

If you are using a CMS like WordPress, Joomla, DNN and etc, you can check their website to see what services they can run on. You can also ask your developer about the service the website needs. As we mentioned, your website’s programming language is really important. For example, PHP works on both Linux and Windows hosts. But it has more features and options on Linux so you better have it on a Linux host.

Hope you enjoyed this post if you did, you can visit our blog for more!