apache安装与配置
参考资料
安装Apache
Ubuntu/Debian:
sudo apt-get install apache2
CentOS/Fedora:
sudo yum install httpd
Windows: 下载Apache二进制文件并解压到指定目录。
启动Apache
Ubuntu/Debian:
sudo systemctl start apache2
CentOS/Fedora:
sudo systemctl start httpd
Windows: 在命令行中进入Apache的bin目录,运行
httpd.exe
。配置Apache
Ubuntu/Debian:
sudo systemctl restart apache2
CentOS/Fedora:
sudo systemctl restart httpd
Windows: 停止并重新启动
httpd.exe
。主配置文件通常位于
/etc/apache2/apache2.conf
(Ubuntu/Debian)或/etc/httpd/conf/httpd.conf
(CentOS/Fedora)。修改配置文件后,重启Apache服务以应用更改:
设置虚拟主机
Ubuntu/Debian:
sudo a2ensite your-site.conf
CentOS/Fedora: 直接在
httpd.conf
中配置。在配置文件中添加
<VirtualHost>
块来定义虚拟主机。确保启用虚拟主机配置文件:
测试配置
在浏览器中输入服务器IP地址或域名,查看是否显示Apache默认页面。
使用
apachectl configtest
或httpd -t
命令检查配置文件语法是否正确。防火墙设置
Ubuntu/Debian:
sudo ufw allow 'Apache Full'
CentOS/Fedora:
sudo firewall-cmd --permanent --add-service=http --add-service=https
,然后sudo firewall-cmd --reload
。确保防火墙允许HTTP(端口80)和HTTPS(端口443)流量:
启用Apache开机启动
Ubuntu/Debian:
sudo systemctl enable apache2
CentOS/Fedora:
sudo systemctl enable httpd
Windows: 将Apache服务添加到系统服务中。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。