侧边栏壁纸
博主头像
liveJQ博主等级

沒有乐趣,何来开始

  • 累计撰写 122 篇文章
  • 累计创建 55 个标签
  • 累计收到 2 条评论

Apache 配置特定域名访问

liveJQ
2022-07-08 / 0 评论 / 0 点赞 / 100 阅读 / 1,158 字 / 正在检测是否收录...
广告 广告

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
0
广告 广告

评论区