ubuntu12.04下 安装虚拟主机
来源:互联网 发布:淘宝网裙子款式 编辑:程序博客网 时间:2024/06/02 01:33
爱漂泊人生
ubuntu12.04下 安装虚拟主机
Ubuntu Linux
方法一
一、修改/etc/apache2/sites-available/
1. 打开目录 /etc/apache2/sites-available/, 发现 default 和 default-ssl 两个文件, 其中 default 是 http 虚拟主机服务的配置文件, default-ssl 是配置 https 服务使用的. 可以复制一份 default 文件. 并修改配置文件名, 文件名必须与域名一致 (如:www.1117.com)
2. 打开新建的配置文件, 修改 DocumentRoot, ServerName 和对应的配置目录. 例子如下:
## DocumentRoot 是网站文件存放的根目录# ServerName 是网站域名, 需要跟 DNS 指向的域名一致#<VirtualHost *:最好自定义端口(如801、802)不要和80冲突> ServerAdmin webmaster@dummy-host.example.com DocumentRoot /var/www/1117/ ServerName www.1117.com ErrorLog ${APACHE_LOG_DIR}/www.1117.com-error.log CustomLog ${APACHE_LOG_DIR}/www.1117.com-access.log combined</VirtualHost>3. 通过 a2ensite 激活虚拟主机配置
<span style="color:#c20cb9;"><strong>sudo</strong> a2ensite www.1117.com.com4. 打开目录 /etc/apache2/sites-enabled/, 你会发现所有激活的虚拟主机, 可以通过 a2dissite 进行注销</span>
<span style="color:#c20cb9;"><strong>sudo</strong> a2dissite www.1117.com.com5. 重启 Apache 服务, 激活虚拟主机</span>
<span style="color: #c20cb9;"><strong>sudo</strong> <span style="font-weight: bold;">/etc<span style="font-weight: bold;">/init.d<span style="font-weight: bold;">/apache2 restart</span></span></span></span>
二、配置/etc/hosts 下的主机hosts的文件
1、修改hosts (ubuntu下只能使用特级权限打开编写)
sudo gedit /etc/hosts
2.添加
127.0.0.1 www.1117.com
先保存、后重启服务器
<span style="color: #c20cb9;"><strong>sudo</strong> <span style="font-weight: bold;">/etc<span style="font-weight: bold;">/init.d<span style="font-weight: bold;">/apache2 restart</span></span></span></span>
方法二、
一、虚拟目录
现场模拟:
本来的访问路径为:localhost/demo/demo1
想把访问路径改为:localhost:701/demo1
1、找到sites-available目录
cd /etc/apache2/sites-available
2、创建一个文档demo,把default文档的内容拷贝过去
default文档内容如下(需要修改的地方用红色标记):
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
3、修改
<VirtualHost *:80>改为<VirtualHost *:701>
DocumentRoot /var/www修改成DocumentRoot /var/www/demo
<Directory /var/www/>修改成<Directory /var/www/demo>
4、链接到sites-enabled
sudo ln -s /etc/apache2/sites-available/demo /etc/apache2/sites-enabled/demo
5、修改端口监听文件
打开/etc/apache2的ports.conf,找到NameVirtualHost *:80,在下行添加Listen 801,即
NameVirtualHost *:80
Listen 80
Listen 80
NameVirtualHost *:801
Listen 801
Listen 801
6、重启rewrite服务,重启apache2
sudo a2ensite demo
sudo a2enmod rewrite
sudo service apache2 restart 或者 sudo apachectl restart
ok
二、设置虚拟域名
现场模拟:将localhost改成www.dxw.com
1、打开/etc/的hosts文件
2、在文档上面相应位置加上一行
127.0.0.1 www.dxw.com
ok
0 0
- ubuntu12.04下 安装虚拟主机
- ubuntu12.04下虚拟主机配置
- ubuntu12.04 下安装Xdebug
- ubuntu12.04下安装ZendDebugger
- Ubuntu12.04下安装Eclipse
- ubuntu12.04下安装java7
- Ubuntu12.04下安装mongodb
- Ubuntu12.04下安装JDK
- Ubuntu12.04下安装eclipse
- Ubuntu12.04下安装Mysql
- ubuntu12.04下安装QT
- Ubuntu12.04下安装MyEclipse10
- ubuntu12.04下安装jdk7
- Ubuntu12.04下安装tomcat7
- ubuntu12.04下安装JDK7
- ubuntu12.04下安装Metasploit
- Ubuntu12.04下JDK安装
- Ubuntu12.04下安装Git
- 我的博客即将入驻“云栖社区”,诚邀技术同仁一同入驻。
- NCBI中Entrez Direct的使用
- eclipse.ini
- web.xml 中的listener、 filter、servlet 加载顺序及其详解
- 日经春秋 20160219
- ubuntu12.04下 安装虚拟主机
- Linux读写物理内存的实践环节
- 常用快捷键
- 我的理解 RESTful Api 架构
- php读MySQL
- 常用数学符号的 LaTeX 表示方法
- hdu 2674 N!Again
- 如何手机访问电脑服务器上的网页?
- 欢迎使用CSDN-markdown编辑器