在Ubuntu上安装和配置Apache Web服务器的步骤如下:
sudo apt update
sudo apt install apache2
安装完成后,Apache服务将会被自动启动。
sudo systemctl status apache2
sudo ufw allow 'Apache Full'
/etc/apache2/ports.conf
文件,找到 Listen 80
并修改为 Listen 5000
。/etc/apache2/apache2.conf
文件,找到以下配置片段:<Directory/>
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
/mnt/www
:<Directory /mnt/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
/etc/apache2/sites-available/000-default.conf
文件,添加或修改以下内容:<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
sudo systemctl reload apache2
sudo apt install openssl
sudo a2enmod ssl
sudo apache2-ssl-certificate
sudo openssl req -x509 -newkey rsa:1024 -keyout apache.pem -out apache.pem -nodes -days 999
sudo cp /etc/apache2/sites-available/default-ssl.conf /etc/apache2/sites-available/001-ssl
sudo nano /etc/apache2/sites-available/001-ssl
<VirtualHost *:443>
ServerName example.com
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.pem
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
sudo a2ensite 001-ssl
sudo systemctl restart apache2
在浏览器中输入服务器的IP地址或域名,例如 http://localhost
或 http://your_server_ip
,如果看到Apache默认欢迎页面,说明安装成功。
以上步骤涵盖了在Ubuntu上安装和配置Apache的基本流程,包括安装、配置虚拟主机以及启用HTTPS。根据实际需求,您可能还需要进行更多的定制和优化。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: PHPStorm在Ubuntu上如何进行性能调优