Apache 配置多站点、多端口访问,及httpd-vhosts.conf文件配置说明


 

1. 修改httpd.conf文件:

  1. 找到类似如下代码:
    #Listen 12.34.56.78:80

    在此行之下添加想要监听的端口,如:

    #Listen 12.34.56.78:80
    Listen 8080

     

  2. 找到如下代码:
    # Virtual hosts

    去除此行下一行的注释,如:

    # Virtual hosts
    Include /etc/httpd/extra/httpd-vhosts.conf

     

  3. 保存并关闭httpd.conf

 

2. 修改httpd-vhosts.conf文件:

  1. 找到之前取消注释路径对应的httpd-vhosts.conf文件
  2. 添加如下代码(请根据需求自行配置):
    <VirtualHost *:8080>
        ServerAdmin xmsb.example.com
        ServerName www.xmsb.com
        DocumentRoot "/usr/local/apache/htdocs"
        ErrorLog "logs/wherein.com-error.log"
        CustomLog "logs/wherein.com-access.log" combined
        <Directory "/usr/local/apache/htdocs">
            Options FollowSymLinks IncludesNoExec Indexes
            DirectoryIndex index.html index.htm index.php
            AllowOverride all
            Require all granted
        </Directory>
    </VirtualHost>

     

  3. 保存并关闭httpd-vhosts.conf

 

3. 重启apache,开放防火墙对应端口


 

httpd-vhosts.conf配置说明:

<VirtualHost *:8080>
    # 管理员邮箱地址
    ServerAdmin xmsb.example.com
    
    # 访问域名
    ServerName www.xmsb.com
    
    # 项目入口文件夹
    DocumentRoot "/usr/local/apache/htdocs"
    
    # 错误日志文件路径
    ErrorLog "logs/wherein.com-error.log"
    
    # 日志文件路径,并指明日志文件格式 combined/common
    CustomLog "logs/wherein.com-access.log" combined
    
    # 设置权限
    <Directory "/usr/local/apache/htdocs">
        # Options参数如下:
        # Indexes 允许目录浏览
        # MultiViews 允许内容协商的多重视图
        # All 包含除MultiViews之外的所有特性,如果没有Options语句,默认为All
        # ExecCGI 允许在该目录下执行CGI脚本
        # FollowSymLinks 可以在该目录中使用符号连接
        # Includes 允许服务器端包含功能
        # IncludesNoExec 允许服务器端包含功能,但禁用执行CGI脚本
        Options FollowSymLinks IncludesNoExec Indexes
        
        # 访问目录后进入的默认文件
        DirectoryIndex index.html index.htm index.php
        
        # 位于每个目录下.htaccess文件中的指令类型。none为禁止使用.htaccess文件
        AllowOverride all
        
        # Apache-2.4 访问权限
        # Require all granted 允许所有来源的访问
        # Require all denied  拒绝所有来源的访问
        # Require host xmsb.com 允许特定域名访问
        # Require ip 192.168.1 192.168.2 允许特定IP段访问
        Require all granted
    </Directory>
</VirtualHost>

 

posted @ 2020-05-14 17:46  何效名  阅读(1399)  评论(0编辑  收藏  举报