Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set up Apache virtual host in ubuntu 14.04

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to set up Apache virtual host in ubuntu 14.04. the editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article.

Install the Apache website server

Before installing the apache server, let's update our Ubuntu server:

Sudo apt-get update then, install the apache network server with the following command:

After sudo apt-get install apache2 installs the apache server, let's test whether the website server is working properly by URL http:// the IP address of your server.

As you can see, the apache server is already working.

Set up a virtual host

1. Create a virtual directory

Now, let's continue to install the virtual host. As I mentioned earlier, I'm going to build two new virtual hosts named unixmen1.local and unixmen2.local.

Create a public folder to store the data of the two virtual hosts.

First, let's create a directory for the unixmen1.local site:

Sudo mkdir-p / var/www/unixmen1.local/public_html then, create a directory for the for unixmen2.local site:

Sudo mkdir-p / var/www/unixmen2.local/public_html

two。 Set owner and permissions

Only root now has permissions in the above directory. We need to change the ownership of these two directories to ordinary users, not just root users.

Sudo chown-R $USER:$USER / var/www/unixmen1.local/public_html/

Sudo chown-R $USER:$USER / var/www/unixmen2.local/public_html/

The "$USER" variable points to the current logged-in user.

Set read and write permissions to the root directory (/ var/www) of the apache page and its subdirectories so that everyone can read files from the directory.

In this way, sudo chmod-R 755 / var/www/, we have created some folders to store network-related data and assign the necessary permissions and users.

4. Create a sample page for a virtual host

Now, let's add a sample page to the website. As a first step, let's create a sample page for the virtual host unixmen1.local.

Create a sample page for the unixmen1.local virtual host

Sudo vi / var/www/unixmen1.local/public_html/index.html adds the following:

XML/HTML Code copies content to the clipboard

Www.unixmen1.local

Welcome To Unixmen1.local website

Save and close the file.

Similarly, add a sample page to the second virtual host.

Sudo vi / var/www/unixmen2.local/public_html/index.html adds the following:

The code is as follows:

Www.unixmen2.local

Welcome To Unixmen2.local website

Save and close the file.

5. Create a virtual host profile

By default, apache has a default virtual host file called 000-default.conf. We will copy the contents of the 000-default.conf file into our new virtual host configuration file.

Sudo cp / etc/apache2/sites-available/000-default.conf / etc/apache2/sites-available/unixmen1.local.conf

Sudo cp / etc/apache2/sites-available/000-default.conf / etc/apache2/sites-available/unixmen2.local.conf ensures that the virtual host configuration file contains the .conf extension at the end.

Now, modify the unximen1.local.conf file to meet your requirements.

Sudo vi / etc/apache2/sites-available/unixmen1.local.conf makes the relevant changes present directly in the unixmen1 site. ).

The code is as follows:

# The ServerName directive sets the request scheme, hostname and port that

# the server uses to identify itself. This is used when creating

# redirection URLs. In the context of virtual hosts, the ServerName

# specifies what hostname must appear in the request's Host: header to

# match this virtual host. For the default virtual host (this file) this

# value is not decisive as it is used as a last resort host regardless.

# However, you must set it for any further virtual host explicitly.

#

ServerName www.example.com

ServerAdmin webmaster@unixmen1.local

ServerName unixmen1.local

ServerAlias www.unixmen1.local

DocumentRoot / var/www/unixmen1.local/public_html

# Available loglevels: trace8, … , trace1, debug, info, notice, warn

# error, crit, alert, emerg.

# It is also possible to configure the loglevel for particular

# modules, e.g.

#

# LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR} / error.log

CustomLog ${APACHE_LOG_DIR} / access.log comb

# For most configuration files from conf-available/, which are

# enabled or disabled at a global level, it is possible to

# include a line for only one particular virtual host. For example the

# following line enables the CGI configuration for this host only

# after it has been globally disabled with "a2disconf".

#

# Include conf-available/serve-cgi-bin.conf

"after modifying the virtual host file, disable the default virtual host configuration (000.default.conf), and then enable the new virtual host configuration, as shown below."

The code is as follows:

Sudo a2dissite 000-default.conf

Sudo a2ensite unixmen1.local.conf

Sudo a2ensite unixmen2.local.conf

Finally, restart the apache server.

Sudo service apache2 restart

okay. Now, we have successfully configured the apach virtual host on our Ubuntu server

Test virtual host

Edit / tc/hosts file

Sudo vi / etc/hosts add the virtual domain name shown below at the end of the file.

192.168.1.250 unixmen1.local192.168.1.250 unixmen2.local saves and closes the file.

Open your browser and visit http://unixmen1.local or http://unixmen2.local. You will see the sample page we created earlier.

Unixmen1.local test page:

This is how to set up the Apache virtual host in ubuntu 14.04. the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report