apache2安装及配置
1.下载及安装apache2的命令
sudo apt install apache2
2.配置自定义监听虚拟端口
选择暂未使用到的端口设置为自定义端口,我这里选择8000
sudo vi /etc/apache2/ports.conf
Listen 80 #默认存在的
Listen 8000 #新加入未用到的端口
3.配置端口监听属性
打开以下文件
sudo vi /etc/apache2/sites-enabled/000-default.conf
添加如下: 我自定义的根目录是/home/userroot/mylocalhost
邮箱可自行添加
<VirtualHost *:8000>
ServerAdmin xxxxxxxx@qq.com
DocumentRoot /home/userroot/mylocalhost
<Directory /home/userroot/mylocalhost>
AllowOverride none
Require all denied
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
4.重新启动服务器
service apache2 restart
5.查看是否配置成功
在网页上输入ip加端口看能否查看到自定义的根目录
先查看服务器IP地址:
ifconfig
浏览器上输入:可在自定义的目录下添加相应文档,用于查看能否使用浏览器看到
http://192.168.5.200:8000/