apache 配置网站目录,虚拟目录,新端口

1 配置网站目录,以ubuntu为例

   1)打开apache的默认配置文件夹:cd /etc/apache2/sites-available  

   2)打开配置文件,本机为sudo vi  000-default.conf

   3) 修改路径

<VirtualHost *:80>

        ServerAdmin webmaster@localhost
        DocumentRoot /data/test

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

2 配置虚拟目录,以windows为例

1)打开httpd.conf,新增一行代码

<IfModule alias_module>

    ScriptAlias /cgi-bin/ "D:/cgi-bin/"
    # 设置站点别名,别名与访问路径是相关的,取任何名称都可以(除特殊)  
    Alias /test "E:/test "  
    
</IfModule>

2) 接着添加下面几行代码

<Directory E:/test>  
    Options Indexes FollowSymLinks     
    AllowOverride None     
    Order allow,deny     
    Allow from all  
</Directory>  

3 配置新端口,以ubuntu为例

1)打开apache的默认配置文件夹:cd /etc/apache2/

2)修改端口文件 sudo vi ports.conf 新增一行

Listen 80
Listen 83

3)切换配置默认目录 cd /etc/apache2/sites-available  

4)配置新增的端口映射sudo vi  000-default.conf 添加几行代码

<VirtualHost *:83>

        ServerAdmin webmaster@localhost
        DocumentRoot /data/newtest

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

4 以上操作之后,均需要重启apache,以ubuntu为例

  sudo /etc/init.d/apache2 restart

原文地址:https://www.cnblogs.com/mengsx/p/5066706.html