UbuntuApach Virtual Host

Source: Internet
Author: User
UbuntuApach Virtual Host-Linux Enterprise Application-Linux server application information. The following is a detailed description. Target
1.
Create an IP-based Vm for overall testing of a project
2.
Create a user-based Vm for testing your code

Start

Create the directory structure of the VM

Sudo/home/www
Cd/home/www
Sudo mkdir 192.168.0.20.192.168.0.252
Cd 192.168.0.133
Sudo mkdir cgi-bin htdocs logs db
Cd ../192.168.0.252
Sudo mkdir cgi-bin htdocs logs db
Tree/home/www
/Home/www
| -- 192.168.0.20.
| -- Cgi-bin
| -- Db
| -- Htdocs
| '-- Logs
'-- 192.168.0.252
| -- Cgi-bin
| -- Db
| -- Htdocs
'-- Logs

1.
To create two IP-based virtual hosts on 192.168.0.252 and 192.168.0.252, the directories 192.168.0.20.and 192.168.0.252 are created under/home/www respectively.
2.
The cgi-bin subdirectory is used to store CGI scripts.
3.
The database subdirectory is used to store the SQLite database.
4.
The htdocs subdirectory is used to store site documents.
5.
The logs subdirectory is used to store site logs.

Create a VM management account and Set Directory Permissions

Sudo useradd-g www-data-d/home/www/192.168.0.20.wuser1
Sudo useradd-g www-data-d/home/www/192.168.0.252 wuser2
Sudo passwd wuser1
Sudo passwd wuser2
Sudo chown-R wuser1.www-data/home/www/192.168.0.133
Sudo chown-R wuser2.www-data/home/www/192.168.0.252

1.
Assign the administrator of the 192.168.0.20.vm to wuser1, assign the administrator of the 192.168.0.252 VM to wuser2, and allow them to log on through ssh.
2.
The master groups of wuser1 and wuser2 are both set to www-data. The convenience of this setting is: if the site contains the Apache process writeable content, you only need to add the group writeable permission.

Configure Virtual Network Interface and host name resolution

Run the following command:

Sudo vim/etc/network/interfaces

Add the following configuration

Auto eth0: 1
Iface eth0: 1 inet static
Address 192.168.0.20.
Netmask 255.255.255.0
Network 192.168.0.0
Broadcast 192.168.0.255
Gateway 192.168.0.1
Auto eth0: 2
Iface eth0: 2 inet static
Address 192.168.0.252
Netmask 255.255.255.0
Network 192.168.0.0
Broadcast 192.168.0.255
Gateway 192.168.0.1

Run the following command to restart the network service:

Sudo/etc/init. d/networking restart

Add the following lines to the/etc/hosts file:

192.168.0.20.web1.example.com web1
192.168.0.252 web2.example.com web2

Configure Apache

S1. create a new file 192.168.0.20.in the/etc/apache2/sites-available/directory and add the following configuration

/Etc/apache2/sites-available/192.168.0.20.


DocumentRoot "/home/www/192.168.0.20./ htdocs /"

Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow, deny
Allow from all


ScriptAlias/cgi-bin // home/www/192.168.0.133/cgi-bin/

AllowOverride None
Options + ExecCGI-MultiViews + SymLinksIfOwnerMatch
Order allow, deny
Allow from all


ErrorLog/home/www/192.168.0.20./ logs/error. log
CustomLog/home/www/192.168.0.20./ access. log combined


S2. create a new file 192.168.0.252 in the/etc/apache2/sites-available/directory and add the following configuration

/Etc/apache2/sites-available/192.168.0.252


DocumentRoot "/home/www/192.168.0.252/htdocs /"

Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow, deny
Allow from all


ScriptAlias/cgi-bin // home/www/192.168.0.252/cgi-bin/

AllowOverride None
Options + ExecCGI-MultiViews + SymLinksIfOwnerMatch
Order allow, deny
Allow from all


ErrorLog/home/www/192.168.0.252/logs/error. log
CustomLog/home/www/192.168.0.252/access. log combined


S3. restart Apache

Sudo a2enmod rewrite
Sudo a2enmod php5
Sudo a2enmod perl
Sudo a2enmod mod_python
Sudo a2ensite 192.168.0.133
Sudo a2ensite 192.168.0.252
Sudo/etc/init. d/apache2 restart







Configure the upload of site content
FTP Server

S1: run the following command to install proftpd:

Sudo apt-get install proftpd-doc

S2. use the default configuration to upload and download local users.
Samba Server

S1. use the following command

Sudo vi/etc/samba/smb. conf

Add the following configuration lines:

/Etc/samba/smb. conf

[Homes]
Comment = Home Directories
Browseable = no
Writable = yes
Create mask = 0644
Directory mask = 0755

S2. configure Samba users to add Samba users using the following command:

Sudo smbpasswd-a wuser1
Sudo smbpasswd-a wuser2

S3. start the Samba server

Sudo/etc/init. d/samba restart

Create a user-based VM

*
Developers may not have created a development environment on Windows clients.
*
To enable each developer to test their own code, they can create user-based virtual hosts.

Create a user account

Sudo useradd-g www-data-m user1
Sudo useradd-g www-data-m user2
Sudo passwd user1
Sudo passwd user2

1.
You need to create the public_html sub-directory under the Home Directory and put the Web document in it. You can use the URL http: // IPorHostname /~ Username
2.
For CGI development, you also need to create the cgi-bin subdirectory under the home directory.

Configure Apache

Use the following command to enable the userdir module:

Sudo a2enmod userdir

For CGI development, you need to modify/etc/apache2/mod-available/userdir. conf


UserDir public_html
UserDir disabled root


AllowOverride FileInfo AuthConfig Limit
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec


ScriptAliasMatch ~ ([A-z] +)/cgi-bin/(. *)/home/$1/cgi-bin/$2
# Add this row, which means matching ~ User_name/cgi-bin/cgi_name automatically maps to the/home/user_name/cgi-bin/cgi-name script


About default Virtual Hosts
In Ubuntu, the file/etc/apache2/sites-available/default is configured with the default virtual host. The default root document directory of the VM is/var/www by default. To facilitate backup, it is best to store all the Web content in the/home/www directory, therefore, you can set the root document directory of the default VM to a subdirectory under/home/www by default.
Create the directory structure of the VM

Cd/home/www
Sudo mkdir 192.168.0.222
Cd 192.168.0.222
Sudo mkdir cgi-bin htdocs

Create a VM management account and Set Directory Permissions

Sudo useradd-g www-data-d/home/www/192.168.0.222 wdefault
Sudo passwd wdefault
Sudo chown-R wdefault. www-data/home/www/192.168.0.222

Configure Apache

S1. create a new file 192.168.0.222 in the/etc/apache2/sites-available/directory and add the following configuration

/Etc/apache2/sites-available/192.168.0.222


DocumentRoot "/home/www/192.168.0.222/htdocs /"

Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow, deny
Allow from all


ScriptAlias/cgi-bin // home/www/192.168.0.222/cgi-bin/

AllowOverride None
Options + ExecCGI-MultiViews + SymLinksIfOwnerMatch
Order allow, deny
Allow from all


ErrorLog/var/log/apache2/error. log
CustomLog/var/log/apache2/access. log combined

Alias/doc/"/usr/share/doc /"

Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny, allow
Deny from all
Allow from 192.168.0.0/255.255.255.0



S2. restart Apache

Sudo a2dissite default
Sudo a2ensite 192.168.0.222
Sudo/etc/init. d/apache2 restart
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.