下面按最常见的使用场景给你一份“Apache 怎么配置”的实用指南(以 Linux:Ubuntu / CentOS 为例,Windows 类似但路径不同)。
sudo apt update
sudo apt install apache2
sudo yum install httpd
# 或
sudo dnf install httpd
启动并设置开机自启:
# Ubuntu
sudo systemctl start apache2
sudo systemctl enable apache2
# CentOS
sudo systemctl start httpd
sudo systemctl enable httpd
/etc/apache2/apache2.conf/etc/apache2/sites-available//etc/apache2/sites-enabled//etc/apache2/mods-available//etc/httpd/conf/httpd.conf/etc/httpd/conf.d/sudo mkdir -p /var/www/example.com/public_html
sudo chown -R $USER:$USER /var/www/example.com
Ubuntu
sudo nano /etc/apache2/sites-available/example.com.conf
内容:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/example.com/public_html
<Directory /var/www/example.com/public_html>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
sudo a2ensite example.com
sudo a2dissite 000-default
sudo systemctl reload apache2
CentOS 直接放在 conf.d 即可。
DirectoryIndex index.php index.html
# Ubuntu
sudo a2enmod rewrite
sudo systemctl restart apache2
Options -Indexes
sudo apt install certbot python3-certbot-apache
sudo certbot --apache -d example.com
sudo ufw allow 80
sudo ufw allow 443
或 CentOS:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
# Ubuntu
tail -f /var/log/apache2/error.log
# CentOS
tail -f /var/log/httpd/error_log
我可以直接给你一份可直接用的配置。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。