mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
a71aa7de9e
renamed: 10 Linux Platforms Meant For Embedded Systems.md -> 201406/10 Linux Platforms Meant For Embedded Systems.md renamed: 20140527 4MLinux 9.0 Beta Is a 55 MB Operating System That Has It All.md -> 201406/20140527 4MLinux 9.0 Beta Is a 55 MB Operating System That Has It All.md renamed: 20140527 A Complete Historical Timeline of Linux Evolution.md -> 201406/20140527 A Complete Historical Timeline of Linux Evolution.md renamed: 20140528 Setup Backup Server Using Bacula And Webmin On Ubuntu 14.04.md -> 201406/20140528 Setup Backup Server Using Bacula And Webmin On Ubuntu 14.04.md renamed: 20140528 Why We Shouldn't Accept Bad Linux Ports.md -> 201406/20140528 Why We Shouldn't Accept Bad Linux Ports.md renamed: 20140529 Add Windows Like Bottom Taskbar In Ubuntu Unity 14.04.md -> 201406/20140529 Add Windows Like Bottom Taskbar In Ubuntu Unity 14.04.md renamed: 20140529 Command Line Tuesdays--The Introductory.md -> 201406/20140529 Command Line Tuesdays--The Introductory.md renamed: 20140529 How To Share Disks In VirtualBox Between Linux Guest OS.md -> 201406/20140529 How To Share Disks In VirtualBox Between Linux Guest OS.md renamed: 20140529 Install RainLoop Webmail (A Web Based Email Client) using 'Nginx and Apache' in Arch Linux.md -> 201406/20140529 Install RainLoop Webmail (A Web Based Email Client) using 'Nginx and Apache' in Arch Linux.md renamed: 20140529 What is a good terminal emulator on Linux.md -> 201406/20140529 What is a good terminal emulator on Linux.md renamed: 20140529 Why No Flash Support for Linux Is Good for Open Source.md -> 201406/20140529 Why No Flash Support for Linux Is Good for Open Source.md renamed: 20140530 Fix 'Cannot Add PPA' Error In Ubuntu 14.04 and Linux Mint.md -> 201406/20140530 Fix 'Cannot Add PPA' Error In Ubuntu 14.04 and Linux Mint.md renamed: 20140530 How To Install Linux On A MacBook Pro Retina.md -> 201406/20140530 How To Install Linux On A MacBook Pro Retina.md renamed: 20140530 Linux script command--A recorder inside your Terminal.md -> 201406/20140530 Linux script command--A recorder inside your Terminal.md renamed: 20140603 App Grid Is A Superior Ubuntu Software Center Alternative.md -> 201406/20140603 App Grid Is A Superior Ubuntu Software Center Alternative.md renamed: 20140603 Linux Foundation to donate portion of membership fees to Code.org.md -> 201406/20140603 Linux Foundation to donate portion of membership fees to Code.org.md renamed: 20140603 Write your first Linux Kernel module.md -> 201406/20140603 Write your first Linux Kernel module.md renamed: 20140604 Command line secrets.md -> 201406/20140604 Command line secrets.md renamed: 20140604 Setup Virtual Hosts In Apache On Ubuntu 14.04 LTS.md -> 201406/20140604 Setup Virtual Hosts In Apache On Ubuntu 14.04 LTS.md renamed: 20140607 Cup 2014 Brazil--Watch FIFA World Cup 2014 Competition in Your Linux Desktop.md -> 201406/20140607 Cup 2014 Brazil--Watch FIFA World Cup 2014 Competition in Your Linux Desktop.md renamed: 20140607 How To Extract Images From Videos Using ffmpeg.md -> 201406/20140607 How To Extract Images From Videos Using ffmpeg.md renamed: 20140607 How To Install iCup 2014 In Linux.md -> 201406/20140607 How To Install iCup 2014 In Linux.md renamed: 20140607 Linux--Bash Delete All Files In Directory Except Few.md -> 201406/20140607 Linux--Bash Delete All Files In Directory Except Few.md renamed: 20140607 New OpenSSL breach is no Heartbleed-but needs to be taken seriously.md -> 201406/20140607 New OpenSSL breach is no Heartbleed-but needs to be taken seriously.md renamed: 20140607 Nuvola Player 2.4.0 Released -- A Online Cloud Music Player for Linux.md -> 201406/20140607 Nuvola Player 2.4.0 Released -- A Online Cloud Music Player for Linux.md renamed: 20140607 Practical Interview Questions and Answers on Linux Shell Scripting.md -> 201406/20140607 Practical Interview Questions and Answers on Linux Shell Scripting.md renamed: 20140607 Steam Hits The Big 500 For Linux Games.md -> 201406/20140607 Steam Hits The Big 500 For Linux Games.md renamed: 20140607 Ubuntu One Formally Shuts Down.md -> 201406/20140607 Ubuntu One Formally Shuts Down.md renamed: 20140609 How To Know If Your System Has USB 3.0 Port In Linux [Quick Tip].md -> 201406/20140609 How To Know If Your System Has USB 3.0 Port In Linux [Quick Tip].md renamed: 20140609 Open Source LDAP Solutions.md -> 201406/20140609 Open Source LDAP Solutions.md renamed: "20140609 OpenELEC 4.0.4 \347\216\260\345\267\262\345\217\221\345\270\203, \345\237\272\344\272\216 XBMC 13.1 \342\200\234Gotham\342\200\235.md" -> "201406/20140609 OpenELEC 4.0.4 \347\216\260\345\267\262\345\217\221\345\270\203, \345\237\272\344\272\216 XBMC 13.1 \342\200\234Gotham\342\200\235.md" renamed: 20140610 How to set up Internet connection sharing with iptables on Linux.md -> 201406/20140610 How to set up Internet connection sharing with iptables on Linux.md renamed: 20140610 IPFire 2.13 Core 78 Linux Firewall OS Receives OpenSSL Fixes.md -> 201406/20140610 IPFire 2.13 Core 78 Linux Firewall OS Receives OpenSSL Fixes.md renamed: 20140610 Open Source SDN Project OpenDaylight Adds New Members.md -> 201406/20140610 Open Source SDN Project OpenDaylight Adds New Members.md renamed: 20140610 Top 7 Desktop Environment For Linux.md -> 201406/20140610 Top 7 Desktop Environment For Linux.md renamed: 20140611 HTG Explains--What' s the Difference Between Linux and BSD.md -> 201406/20140611 HTG Explains--What' s the Difference Between Linux and BSD.md renamed: 20140611 How to Prevent Other Users From Accessing Your Home Directory in Ubuntu 14.04.md -> 201406/20140611 How to Prevent Other Users From Accessing Your Home Directory in Ubuntu 14.04.md renamed: 20140612 Command Line Tuesdays--Part One.md -> 201406/20140612 Command Line Tuesdays--Part One.md renamed: 20140612 Dpkg Vulnerabilities Closed in Ubuntu 14.04.md -> 201406/20140612 Dpkg Vulnerabilities Closed in Ubuntu 14.04.md renamed: 20140616 How To Install Numix Icon Theme In Fedora 20.md -> 201406/20140616 How To Install Numix Icon Theme In Fedora 20.md renamed: 20140616 Ubuntu Desktop Next 14.10 Images Available to Download.md -> 201406/20140616 Ubuntu Desktop Next 14.10 Images Available to Download.md renamed: 20140616 Ubuntu for Phones Activated on 10,000 Devices.md -> 201406/20140616 Ubuntu for Phones Activated on 10,000 Devices.md renamed: 20140617 14 Apps To Boost Ubuntu.md -> 201406/20140617 14 Apps To Boost Ubuntu.md renamed: 20140619 Improve Battery Life with Laptop Mode Tools 1.65.md -> 201406/20140619 Improve Battery Life with Laptop Mode Tools 1.65.md renamed: 20140619 Red Hat to Acquire eNovance, Focus Together on OpenStack.md -> 201406/20140619 Red Hat to Acquire eNovance, Focus Together on OpenStack.md renamed: 20140620 Celebrating 30 Years of X.md -> 201406/20140620 Celebrating 30 Years of X.md renamed: 20140620 ENCRYPT DNS TRAFFIC IN LINUX WITH DNSCRYPT (VIA OPENDNS).md -> 201406/20140620 ENCRYPT DNS TRAFFIC IN LINUX WITH DNSCRYPT (VIA OPENDNS).md renamed: 20140620 How to enable testing and unstable repository on Debian.md -> 201406/20140620 How to enable testing and unstable repository on Debian.md renamed: 20140625 Canonical Debuts 'Orange Box' for Ubuntu OpenStack Cloud Demos.md -> 201406/20140625 Canonical Debuts 'Orange Box' for Ubuntu OpenStack Cloud Demos.md renamed: 8 examples of findmnt command to check mounted file systems on Linux.md -> 201406/8 examples of findmnt command to check mounted file systems on Linux.md renamed: Bash Getopts--Scripts with Command Line Options.md -> 201406/Bash Getopts--Scripts with Command Line Options.md renamed: Collectl--An Advanced All-in-One Performance Monitoring Tool for Linux.md -> 201406/Collectl--An Advanced All-in-One Performance Monitoring Tool for Linux.md renamed: Fix Adobe Flash Player Issue In Chromium In Ubuntu 14.04.md -> 201406/Fix Adobe Flash Player Issue In Chromium In Ubuntu 14.04.md renamed: Guide To Install Ubuntu 14.04 In Dual Boot Mode With Windows 8 Or 8.1 UEFI.md -> 201406/Guide To Install Ubuntu 14.04 In Dual Boot Mode With Windows 8 Or 8.1 UEFI.md renamed: How To Install 'California' Calendar App in Ubuntu 14.04.md -> 201406/How To Install 'California' Calendar App in Ubuntu 14.04.md renamed: How To Remove Drive Icons From Unity Launcher In Ubuntu 14.04 [Beginner Tips].md -> 201406/How To Remove Drive Icons From Unity Launcher In Ubuntu 14.04 [Beginner Tips].md renamed: How to Install Windows 8.1 and Ubuntu 14.04 LTS on the Same Computer.md -> 201406/How to Install Windows 8.1 and Ubuntu 14.04 LTS on the Same Computer.md renamed: How to download webcomics from the command line on Linux.md -> 201406/How to download webcomics from the command line on Linux.md renamed: How to launch applications differently with Gnome-Pie on Linux desktop.md -> 201406/How to launch applications differently with Gnome-Pie on Linux desktop.md renamed: How to manage Linux containers with Docker on Ubuntu.md -> 201406/How to manage Linux containers with Docker on Ubuntu.md renamed: How to manage ip addresses and subnets with phpIPAM.md -> 201406/How to manage ip addresses and subnets with phpIPAM.md renamed: How to manage passwords from the command line on Linux.md -> 201406/How to manage passwords from the command line on Linux.md renamed: How to monitor Nginx web server from the command line in real time.md -> 201406/How to monitor Nginx web server from the command line in real time.md renamed: How to set up a web-based lightweight system monitor on Linux.md -> 201406/How to set up a web-based lightweight system monitor on Linux.md renamed: How to take a screenshot from the command line on Linux.md -> 201406/How to take a screenshot from the command line on Linux.md renamed: How to take full length screenshots of websites via terminal.md -> 201406/How to take full length screenshots of websites via terminal.md renamed: How to use LVM in Linux.md -> 201406/How to use LVM in Linux.md renamed: How to verify DDOS attack with netstat command on Linux Terminal.md -> 201406/How to verify DDOS attack with netstat command on Linux Terminal.md renamed: Install SoundCloud In Ubuntu 14.04.md -> 201406/Install SoundCloud In Ubuntu 14.04.md renamed: Linux Pros' Top Command Line Secrets.md -> 201406/Linux Pros' Top Command Line Secrets.md renamed: Linux Terminal--Dstat monitoring tools.md -> 201406/Linux Terminal--Dstat monitoring tools.md renamed: Making Linux Feel at Home.md -> 201406/Making Linux Feel at Home.md renamed: Open Source's Cult Of Personality Is Dying--Thankfully.md -> 201406/Open Source's Cult Of Personality Is Dying--Thankfully.md renamed: Pros' Secrets and Red Hat 7 and PCLinuxOS 2014.05 Reviews.md -> 201406/Pros' Secrets and Red Hat 7 and PCLinuxOS 2014.05 Reviews.md renamed: Start Practising Linux ip command and Avoid the Habit of Using ifconfig.md -> 201406/Start Practising Linux ip command and Avoid the Habit of Using ifconfig.md renamed: TechView--Linus Torvalds Inventor of Linux.md -> 201406/TechView--Linus Torvalds Inventor of Linux.md renamed: Turn Off Bluetooth By Default In Ubuntu 14.04 [Quick Tip].md -> 201406/Turn Off Bluetooth By Default In Ubuntu 14.04 [Quick Tip].md renamed: Ubuntu Linux Community Manager Jono Bacon Leaves Canonical.md -> 201406/Ubuntu Linux Community Manager Jono Bacon Leaves Canonical.md renamed: What Heartbleed Teaches Us--Be An Open Source Contributor, Not Just A User.md -> 201406/What Heartbleed Teaches Us--Be An Open Source Contributor, Not Just A User.md renamed: Why htop Command Compete Linux top Command.md -> 201406/Why htop Command Compete Linux top Command.md
234 lines
9.1 KiB
Markdown
234 lines
9.1 KiB
Markdown
在Ubuntu 14.04 LTS系统中设置Apache虚拟主机
|
||
================================================================================
|
||
|
||
**虚拟主机**常用于在一个单独的IP地址上提供多个域名的网站服务。如果有人想在单个VPS的单个IP地址运行多个网站,这是非常有用的。
|
||
|
||
在这个教程中,让我告诉你如何设置在Ubuntu 14.04 LTS的Apache网页服务器设置虚拟主机。请注意,这个教程只针对Ubuntu14.04的32位版本。
|
||
|
||
我不保证它也可以工作在其它更低的Ubuntu版本或者Ubuntu衍生版本(虽然可能过程是类似的)。
|
||
|
||
###方案###
|
||
|
||
在这个教程中,我会使用Ubuntu 14.04 32位 LTS,并搭建2个测试网站分别命名为“**unixmen1.local**” 和 “**unixmen2.local**”.我的测试机分别为**192.168.1.250/24**和**server.unixmen.local**。你可以根据你的需要更改虚拟域名。
|
||
|
||
###安装Apache网站服务器###
|
||
|
||
安装apache服务器之前,我们来更新一下我们的Ubuntu服务器:
|
||
|
||
sudo apt-get update
|
||
|
||
然后,用下面命令来安装apache网络服务器:
|
||
|
||
sudo apt-get install apache2
|
||
|
||
安装apache服务器之后,让我们通过这个URL **http://你的服务器的IP地址/** 来测试网站服务器是否正常工作
|
||
![](http://180016988.r.cdn77.net/wp-content/uploads/2014/06/Apache2-Ubuntu-Default-Page-It-works-Mozilla-Firefox_001.png)
|
||
|
||
如你所见,apache服务器已经工作了。
|
||
|
||
###设置虚拟主机###
|
||
|
||
#### 1.创建虚拟目录 ##
|
||
|
||
现在,让我们继续安装虚拟主机。正如我先前所述,我要新建2台虚拟主机分别命名为“**unixmen1.local**”和“**unixmen2.local**”.
|
||
|
||
创建一个公用的文件夹来存放这两台虚拟主机的数据。
|
||
|
||
首先,让我们为unixmen1.local这个站点创建一个目录:
|
||
|
||
sudo mkdir -p /var/www/unixmen1.local/public_html
|
||
|
||
接着,为for unixmen2.local站点创建一个目录:
|
||
|
||
sudo mkdir -p /var/www/unixmen2.local/public_html
|
||
|
||
### 2. 设置所有者和权限 ####
|
||
|
||
上面目录现在只有root拥有权限。我们需要修改这2个目录的拥有权给普通用户,而不仅仅是root用户。
|
||
|
||
sudo chown -R $USER:$USER /var/www/unixmen1.local/public_html/
|
||
sudo chown -R $USER:$USER /var/www/unixmen2.local/public_html/
|
||
|
||
“**$USER**”变量指向了当前的登录用户。
|
||
|
||
设置读写权限给apache网页根目录(/var/www)及其子目录,这样每个人都可以从目录中读取文件。
|
||
|
||
sudo chmod -R 755 /var/www/
|
||
|
||
这样,我们就创建好了一些文件夹来保存网络相关数据并分配必要的权限和所属用户。
|
||
|
||
#### 4. 为虚拟主机创建示例页 ####
|
||
|
||
现在,我们给网站增加示例页。第一步,让我们给虚拟主机**unixmen1.local**创建一个示例页。
|
||
|
||
给unixmen1.local虚拟主机创建一个示例页,
|
||
|
||
sudo vi /var/www/unixmen1.local/public_html/index.html
|
||
|
||
添加以下内容:
|
||
|
||
<html>
|
||
<head>
|
||
<title>www.unixmen1.local</title>
|
||
</head>
|
||
<body>
|
||
<h1>Welcome To Unixmen1.local website</h1>
|
||
</body>
|
||
</html>
|
||
|
||
|
||
保存并关闭文件。
|
||
|
||
同样的,添加示例页到第二台虚拟主机。
|
||
|
||
sudo vi /var/www/unixmen2.local/public_html/index.html
|
||
|
||
|
||
添加以下内容:
|
||
|
||
<html>
|
||
<head>
|
||
<title>www.unixmen2.local</title>
|
||
</head>
|
||
<body>
|
||
<h1>Welcome To Unixmen2.local website</h1>
|
||
</body>
|
||
</html>
|
||
|
||
保存并关闭文件。
|
||
|
||
#### 5. 创建虚拟主机配置文件####
|
||
|
||
默认情况下,apache有一个默认的虚拟主机文件叫000-default.conf。我们将会复制**000-default.conf**文件内容到我们新的虚拟主机配置文件中。
|
||
|
||
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
|
||
|
||
确保虚拟主机配置文件末尾包含.conf扩展名。
|
||
|
||
现在,修改unximen1.local.conf文件以符合需求。
|
||
|
||
sudo vi /etc/apache2/sites-available/unixmen1.local.conf
|
||
|
||
使相关的变化直接呈现在unixmen1站点中(译注:以“#”开头的注释行可以忽略。)。
|
||
|
||
<VirtualHost *:80>
|
||
# 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 combined
|
||
|
||
# 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
|
||
</VirtualHost>
|
||
|
||
|
||
同理,修改第二台主机文件。
|
||
|
||
sudo vi /etc/apache2/sites-available/unixmen2.local.conf
|
||
|
||
使相关的修改在unixmen2 站点呈现出来。
|
||
|
||
<VirtualHost *:80>
|
||
# 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@unixmen2.local
|
||
ServerName unixmen2.local
|
||
ServerAlias www.unixmen2.local
|
||
DocumentRoot /var/www/unixmen2.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 combined
|
||
|
||
# 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
|
||
</VirtualHost>
|
||
|
||
|
||
修改虚拟主机文件后,禁用默认的虚拟主机配置(000.default.conf),然后启用新的虚拟主机配置,如下所示。
|
||
|
||
sudo a2dissite 000-default.conf
|
||
sudo a2ensite unixmen1.local.conf
|
||
sudo a2ensite unixmen2.local.conf
|
||
|
||
最后,重启apache服务器。
|
||
|
||
sudo service apache2 restart
|
||
|
||
就是这样。现在,我们成功地配置了apach虚拟主机在我们的Ubuntu服务器上
|
||
|
||
###测试虚拟主机###
|
||
|
||
编辑**/etc/hosts**文件,
|
||
|
||
sudo vi /etc/hosts
|
||
|
||
在文件末尾添加如下所示的虚拟域名。
|
||
|
||
192.168.1.250 unixmen1.local
|
||
192.168.1.250 unixmen2.local
|
||
|
||
保存并关闭文件。
|
||
|
||
打开你的浏览器并访问**http://unixmen1.local** 或 **http://unixmen2.local**。你将会看到我们之前创建的示例页。
|
||
|
||
**Unixmen1.local 测试页:**
|
||
|
||
![](http://180016988.r.cdn77.net/wp-content/uploads/2014/06/www.unixmen1.local-Mozilla-Firefox_004.png)
|
||
|
||
|
||
**Unixmen2.local 测试页**
|
||
|
||
![](http://180016988.r.cdn77.net/wp-content/uploads/2014/06/www.unixmen2.local-Mozilla-Firefox_005.png)
|
||
|
||
如果你想从你的远程系统访问这些站点,你需要在你的DNS服务器添加实际域名记录。不过,我没有真实的域名和DNS服务器,我只想通过我的本地系统测试,那么它刚好如我所愿地工作。
|
||
|
||
Cheers!
|
||
|
||
--------------------------------------------------------------------------------
|
||
|
||
via: http://www.unixmen.com/setup-virtual-hosts-apache-ubuntu-14-04-lts/
|
||
|
||
译者:[disylee](https://github.com/disylee) 校对:[wxy](https://github.com/wxy)
|
||
|
||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|