其他分享
首页 > 其他分享> > apache2配置多个端口在不同根目录

apache2配置多个端口在不同根目录

作者:互联网

1.转到apache2根目录

cd /etc/apache2

2.编辑ports.conf

command:vim /etc/apache2/ports.conf
ports.conf文本:
vim /etc/apache2/ports.conf
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

Listen 80

Listen 8090

<IfModule ssl_module>
        Listen 443
</IfModule>

<IfModule mod_gnutls.c>
        Listen 443
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

3.拷贝默认站点 000-default.conf 文件 并修改为你的配置

  cd /etc/apache2/sites-available/
    #复制文件
    cp 000-default.conf test_wbe8090.conf
  # 编辑文件
  vim test_web8090.conf

 

 

 

 

 

 

 

test_web8090.conf代码:
<VirtualHost *:8090>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/test_web8090

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

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

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf

</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

4.转到/etc/apache2/sites-enabled建立软连接

cd /etc/apache2/sites-enabled
建立软连接
sudo ln -s test_web8090.conf ../sites-enabled/test_web8090.conf
来自https://blog.csdn.net/kids_calamus/article/details/87357382?spm=1018.2226.3001.4187de解释:
这一步的目的是建立软链接,不加-s是建立硬链接;
软链接只会在选定的位置上生成一个文件的镜像,不会占用磁盘空间,类似与windows的快捷方式。
硬连接会在选定的位置上生成一个和源文件大小相同的文件,无论是软链接还是硬链接,文件都保持同步变化。
我每次这样操作后面都无法重启apache,所以取消链接,手动复制相同的两个文件了。

取消链接方法:
  # unlink 刚刚链接的文件
  unlink /etc/apache2/sites-enabled/你的配置文件.conf

5.重启apache2

service apache2 restart

6.到服务器打开端口(如果使用的安全组还没开放要服务的端口的话)

———————————————————————————–分割线,出现的问题——————————

按照上面配置好8090端口后,默认情况下访问8090端口应该是会使用/var/www/html/test_web8090作为根目录的,但是实际情况是访问8090端口时会以/var/www/html作为根目录,不断去找配置文件调了很久都没有用,但是后面直接将/etc/apache2/sites-enabled下的默认配置文件000-default.conf文件,直接加上8090端口的配置然后重启apache2服务,结果访问8090端口居然神奇的将test_web8090作为根目录了,就很迷不知道是不是之前哪里出问题了(因为之前已经试过这样子了但是会导致8090端口404not found):

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet


<VirtualHost *:8090>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/test_web8090
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

8090端口正常后又尝试删除sites-enabled和sites_variable目录下的test_web8090全部删除,再重启apache2,发现8090端口保持正常,没有受到影响(迷了)

标签:web8090,8090,端口,apache2,conf,test,根目录
来源: https://www.cnblogs.com/SEEMi/p/15194625.html