Apache通过配置端口访问不同目录

Apache通过配置端口访问不同目录

近期遇到一个http的的需求,要求同一域名,根据端口号不同访问不同的应用,网上资料比较少,收集了一部分,留作记录。

<VirtualHost *:80>

ServerName www.xxxxx.net

DocumentRoot "/xxx"

<Directory "/xxx/">

AllowOverride All Options Indexes FollowSymLinks

Require all granted

</Directory>

</VirtualHost>

<VirtualHost *:8080>

ServerName www.xxxxx.net:8080

DocumentRoot "/xx/xxx"

<Directory "/xx/xxx/">

AllowOverride All Options Indexes FollowSymLinks Require all granted

</Directory>

</VirtualHost>

如上所示,我配置了两个端口80端口访问的是xx目录,而8080端口访问xx目录下的xxx目录。 -

既然配置了端口那么肯定要对端口进行监听才行!

[端口](https://static.oschina.net/uploads/img/201707/20220120_GfzI.png "端口") - 在大约40行的Listen 80

Listen 8080

重启httpd服务

另外还有一种情况

如何设置VirtualHosts以将同一IP上的两个端口指向不同的ServerName

NameVirtualHost *:80

<VirtualHost *:80>
ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot /www/domain
</VirtualHost>

<VirtualHost *:80>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>

参考资料:

https://www.xinnet.com/xinzhi/66/116374.html

https://www.nuomiphp.com/serverfault/zh/602f1fe22ab62a0b3b116dc0.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值