Using Apache to Build ASimple Web Server in Ubuntu 18.04

Source: Internet
Author: User
Keywords ubuntu simple web server linux simple web server create simple web server linux
This article will use Apache to build an ultra- simple web server on Ubuntu 18.04. The whole process is very simple. In addition to explaining the installation of the Apache2 web server, it also explains how Apache can modify the website root directory and default web pages.

Before building a web server, you need to understand several important concepts:
1. web server
In my opinion, a web server is a program running on a computer that provides documents to the entire network or web clients and browsers. We can obtain the information stored in the web server through HTTP requests.

2. The difference between web server and web server
A network server is a dedicated computer that provides certain services to customers in a network environment. In other words, our web server service (program) runs under this kind of computer.

3. Common web servers
Common web servers are Apache, ngnix, IIS
1].Apache
Apache transliteration is Apache, which is the most popular web server in the world. Because of its fast, reliable, and expandable through simple API, it can deploy Python\Perl and other interpreters on it. It has received wide attention and use.

2].Ngnix
The fatal flaw of Apache is that it is a bit difficult to handle a large number of (more than 10,000) requests at the same time. Therefore, a lightweight web server designed by the people of the "battle nation"-Ngnix, nginx can be used under high concurrency. Maintain low resources and high performance than Apache.

3].IIS
iis is the abbreviation of Internet Information Services, which means Internet Information Services. It is a basic Internet service based on Microsoft Windows provided by Microsoft.

1. Installation of Apache2 web server
I believe that I have read some books about building Linux servers, plus my Linux version is Ubuntu 18.04. Friends will wonder if there is no httpd service on their Linux system. In fact, we don’t have to panic at this point, and we don’t need to install a separate httpd service. At this point, you can install an Apache directly, because httpd is the main program of the Apache Hypertext Transfer Protocol (HTTP) server. It is designed as a standalone background process that will create a pool of child processes or threads to handle requests.

Let's take a look at the installation of the new version of Apache2 web server:

1. We do it with one order
sudo apt install apache2 -y

2. After installation, we check whether the Apache service is started
systemctl status apache2

3. Let's take a look at some common commands for operating Apache
Turn on, turn off and restart the server
1], /etc/init.d/apache2 start  //Start Apache service
2], /etc/init.d/apache2 stop  //stop the Apache service
3], /etc/init.d/apache2 restart  //Restart the Apache service

4. Now we can start to access the Apache server we just configured. Open the browser and enter http://127.0.0.1/ (this is the default IP address of the host) or if it is a cloud host, enter the IP address of the cloud host. When we see the following page, it means that the Apache2 service has been successfully working on our server

2. Apache modify the website root directory and default webpage
Let's try to modify the configuration of the web server so that we can access the data specified by ourselves on the web server we built:
1. Modify the root directory

Modify DocumentRoot /var/www/ in 000-default.conf in /etc/apache2/sites-available to the desired directory.

For example: DocumentRoot /var/www/html/mainpage

Excuting an order:
vim /etc/apache2/sites-available/000-default.conf

Modify DocumentRoot /var/www/ in 000-default.conf as follows:

ServerAdmin webmaster@localhost

DocumentRoot /var/www/html  // Generally we default to this as the root directory of the website

Then restart apache:

sudo apache2ctl -k restart

2. Modify the default web page to the page you want

Modify the content in /etc/apache2/mods-available/dir.conf.

Excuting an order:

vim /etc/apache2/mods-available/dir.conf

It turned out to be:

<IfModule mod_dir.c>

DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm

</IfModule>

Just add the /wordpress you want.

<IfModule mod_dir.c>

DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm /wordpress

</IfModule>

In fact, adding files or directories here means that we allow http requests to access the contents of the changed files or directories under /var/www/html:

For example, I added the test directory:

<IfModule mod_dir.c>

DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm /test

</IfModule>

Add a document named index.html inside and write "Hello World!", so we can access through the IP address +/test/index.html

Well, after setting up the web server, we can start our website construction.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.