Linux下Apache配置
- 在Apache配置目录下,找到httpd.conf文件,我的目录是在
/etc/httpd/conf
下 - 打开配置文件,在大概70行的位置上可以看到配置文件的注释:
- 这段注释的大概意思是我们可以通过添加
<VirtualHost></VirtualHost>
标签框来定义虚拟主机,同时会覆盖默认的配置 - 接下来就是自己配置端口了如下:
<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目录。 - 既然配置了端口那么肯定要对端口进行监听才行
- 在大约40行的位置监听80和8080端口
Listen 80
Listen 8080
systemctl restart httpd
重启httpd服务,试着访问一下吧