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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM