检查网络端口的占用情况
确保80和443端口没有被占用。
# apt install net-tools
# netstat -nplt
或者
# apt install lsof
# lsof -i:80
如果需要释放对某个端口的监听,那么终止相关的进程
# kill -9 pid_num
检查防火墙的设置
首先查看防火墙的状态:
# ufw status
如果防火墙开启了,要开放80和443端口
# ufw allow 80
# ufw allow 443
安装apache
# apt update && apt upgrade
# apt install apache2
检查是否安装启动成功
# systemctl status apache2
顺便贴一下其它操作apache的命令
systemctl stop apache2.service
systemctl start apache2.service
systemctl restart apache2.service
systemctl reload apache2.service
此时从浏览器中访问网页,应该可以看到apache提供的默认网页
http://localhost
如果你有公网ip或者域名,此时也可以通过ip和域名从外网访问了
http://vultr.idealand.xyz
拷贝网页
将自己的网页文件拷贝到 /var/www/html/ 文件夹中,替换apahce提供的默认网页
# cd /var/www/html/ && ls
# mv index.html index_apache.html && ls
用putty提供的pscp.exe将本地文件拷贝到服务器
# d:
# cd "D:\Program Files\PuTTY"
# pscp -r D:\buda\dist\* root@idealand.xyz:/var/www/html/
配置https服务
启用ssl模块
# a2enmod ssl
# systemctl restart apache2
# systemctl status apache2
填写ssl证书路径
# cd /etc/apache2/sites-available
# nano default-ssl.conf
用自己的证书的文件路径替换默认的pubkey和privkey的文件路径
启用ssl网站
# a2ensite default-ssl.conf
# systemctl reload apache2
这时就可以访问https网站了
以上如有错漏之处,敬请大家指正。我的联系方式:
微信:TobeBuda
Email/Paypal: jinmin.si@outlook.com
邀请您加入「社区资讯服务」创业微信群,共同探讨打造社区资讯服务的美好未来。
2024年6月2日,6月10日更新
本文参考资料:
https://www.cnblogs.com/dylancao/p/11841191.html
How To Install the Apache Web Server on Ubuntu
Configuring Apache SSL Certificate on Ubuntu 22 | Reintech media