zoukankan      html  css  js  c++  java
  • Ubuntu下apache的多虚拟主机配置

        在ubuntu下,apache的配置文件的路径为/etc/apache2。在此目录下,可以看到http.conf,但是文件确是空的。在ubuntu下,它把apache的配置发散到了各个配置文件中,此目录下的apache2.conf文件,这是个总体配置文件,在此文件中,可以看到Include命令,它把很多其他文件包含进来,其中包括http.conf。因此在http.conf写配置的话,也是生效的。

        下面举例说明多虚拟主机的配置。我有两台机器,一台windows,ip:192.168.1.105, 一台虚拟机ubuntu,ip:192.168.1.115,现在有两个网站运行在ubuntu上做开发,名称分别为phptest和dbmanage,如果通过windows去访问呢?

        在apache2.conf的文件中,可以看到

    image

    其实,sites-enabled是对sites-available的映射,因此我们在sites-available目录下配置就行。在sites-available下复制一份default文件,命名为phptest,然后更改phptest文件就行,phptest文件如下:

     1 <VirtualHost *:80>
     2     ServerAdmin webmaster@localhost
     3     ServerName phptest
     4     ServerAlias www.phptest.com
     5     DocumentRoot /home/dingjing/web/www
     6     <Directory />
     7         Options FollowSymLinks
     8         AllowOverride All
     9     </Directory>
    10     <Directory /home/dingjing/web/www>
    11         Options Indexes FollowSymLinks MultiViews
    12         AllowOverride All
    13         Order allow,deny
    14         allow from all
    15     </Directory>
    16 
    17     ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    18     <Directory "/usr/lib/cgi-bin">
    19         AllowOverride None
    20         Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    21         Order allow,deny
    22         Allow from all
    23     </Directory>
    24 
    25     ErrorLog ${APACHE_LOG_DIR}/error.log
    26 
    27     # Possible values include: debug, info, notice, warn, error, crit,
    28     # alert, emerg.
    29     LogLevel warn
    30 
    31     CustomLog ${APACHE_LOG_DIR}/access.log combined
    32     <IfModule mod_rewrite.c>
    33         RewriteEngine on
    34         RewriteCond %{REQUEST_FILENAME} !-f
    35         RewriteCond %{REQUEST_FILENAME} !-d
    36         RewriteRule !\.(js|ico|gif|jpg|png|css|xml|swf|cur)$ /index.php [NC]
    37     </IfModule>
    38 
    39     Alias /doc/ "/usr/share/doc/"
    40     <Directory "/usr/share/doc/">
    41         Options Indexes MultiViews FollowSymLinks
    42         AllowOverride All
    43         Order deny,allow
    44         Deny from all
    45         Allow from 127.0.0.0/255.0.0.0 ::1/128
    46     </Directory>
    47 
    48 </VirtualHost>

    其中,ServerName是服务器名称,ServerAlias是别名,DocumentRoot配置的是网站的文件目录。在此配置文件中,我们开启了重写规则,见32-37行的配置。

    在此说明的是,基于名称的虚拟主机要配置:NameVirtualHost *:80,可以把此语句写在/etc/apache2/ports.conf文件中。同样方法,可以建立dbmanage文件,在此不再说明。

    此时,文件配置完成,但是新增加的文件没有映射到sites-enable目录,增加映射需要执行:

    image

    此时,sites-enable目录下就有相应的配置文件了,同样步骤操作增加dbmanage文件。

    然后在windows中,配置hosts:

    image

    这样,在windows中就可以访问这两个网站了。

  • 相关阅读:
    telnet -测试端口号
    JMS与MQ详解(有项目)
    Spring JdbcTemplate方法详解
    Spring任务调度器之Task的使用
    基于注解的Spring AOP的配置和使用
    JSONObject转换JSON--将Date转换为指定格式
    request.getParameterMap()使用方法
    python中的内存管理
    python解释器和变量
    理解什么是操作系统
  • 原文地址:https://www.cnblogs.com/dingjing/p/2827228.html
Copyright © 2011-2022 走看看