Apache 服务默认直接通过IP访问默认页面,添加了域名解析后,如果不想让人直接通过IP访问,则可以为其设置ServerName
。
CentOS 7
编辑/usr/local/apache/conf/httpd.conf
Listen 80
ServerName 0.0.0.0
<Directory />
AllowOverride none
Require all denied
</Directory>
DocumentRoot "/var/www/html"
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
编辑/usr/local/apache/conf/extra/httpd-vhosts.conf
Include /usr/local/apache/conf/vhost/*.conf
编辑/usr/local/apache/conf/vhost/default.conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /var/www/web
<Directory /var/www/web>
SetOutputFilter DEFLATE
Options FollowSymLinks
AllowOverride All
Order Deny,Allow
Allow from All
DirectoryIndex index.php index.html index.htm
</Directory>
</VirtualHost>
使配置更改生效
systemctl reload httpd
Ubuntu 20.04
编辑/etc/apache2/sites-available/default.conf
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin admin@livejq.top
DocumentRoot /var/www/web
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
使配置更改生效
systemctl reload apache2
评论区