Ubuntu Apache 2.4 配置-虚拟站点、禁止IP访问
来源:互联网 发布:windows cmd shell 编辑:程序博客网 时间:2024/05/16 01:30
- 配置环境
- 安装Apache2备份原有配置
- 配置虚拟站点禁用IP直接访问
- 修改 etcapache2sites-availablewwwexamplecomconf
- 修改 etcapache2sites-availablewwwtestcomconf
- 启用配置文件wwwexamplecom和wwwtestcom
- 测试访问Windows
- 修改host文件指向域名到wwwexamplecomwwwtestcom
- 测试域名访问
- 附清除Apache 2 配置文件
- 参考链接
配置环境
- Ubuntu Server 16.04
- 域名
www.example.com
,www.test.com
- IP地址
192.168.1.216
要求 输入域名
www.example.com
,www.test.com
能够正常访问,禁止直接输入IP地址访问。
安装Apache2,备份原有配置
apt-get updateapt-get install apache2# 禁用默认站点配置a2dissite 000-default.confservice apache2 reload# 以默认配置为模板,创建 www.example.com, www.test.comcp /etc/apache2/sites-available/000-default.conf \ /etc/apache2/sites-available/www.example.com.confcp /etc/apache2/sites-available/000-default.conf \ /etc/apache2/sites-available/www.test.com.conf# 分别创建网站根目录mkdir /var/www/html/www.example.commkdir /var/www/html/www.test.comchown www-data:www-data /var/www/html/www.example.comchown www-data:www-data /var/www/html/www.test.com
配置虚拟站点,禁用IP直接访问
修改 /etc/apache2/sites-available/www.example.com.conf
# 禁止IP直接访问<VirtualHost *:80> # ServerName 填写你服务器的IP ServerName 192.168.1.216 DocumentRoot /dev/null Redirect 403 / ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined</VirtualHost># 配置虚拟站点 www.example.com<VirtualHost *:80> ServerName www.example.com DocumentRoot /var/www/html/www.example.com # 禁止通过浏览器直接访问Log文件 <Files ~ ".log"> Order allow,deny Deny from all </Files> ErrorLog /var/www/html/www.example.com/error.log CustomLog /var/www/html/www.example.com/access.log combined</VirtualHost>
修改 /etc/apache2/sites-available/www.test.com.conf
# 禁止IP直接访问<VirtualHost *:80> # ServerName 填写你服务器的IP ServerName 192.168.1.216 DocumentRoot /dev/null Redirect 403 / ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined</VirtualHost># 配置虚拟站点 www.test.com<VirtualHost *:80> ServerName www.test.com DocumentRoot /var/www/html/www.test.com # 禁止通过浏览器直接访问Log文件 <Files ~ ".log"> Order allow,deny Deny from all </Files> ErrorLog /var/www/html/www.test.com/error.log CustomLog /var/www/html/www.test.com/access.log combined</VirtualHost>
启用配置文件www.example.com
和www.test.com
a2ensite www.example.com.confa2ensite www.test.com.confservice apache2 reload
测试访问Windows
修改host文件指向域名到www.example.com
,www.test.com
192.168.1.216 www.example.com192.168.1.216 www.test.com
测试域名访问
# 复制默认index.html到两个站点下,测试访问cp /var/www/html/index.html /var/www/html/www.example.com/cp /var/www/html/index.html /var/www/html/www.test.com/
访问www.example.com正常
访问www.test.com正常
访问192.168.1.216禁止
附【清除Apache 2 配置文件】
# 少数模块配置信息无法删除apt-get autoremove --purge apache2
参考链接
- block-direct-ip-access-to-your-server-in-apache-2-4
http://nikles.it/block-direct-ip-access-to-your-server-in-apache-2-4/
阅读全文
0 0
- Ubuntu Apache 2.4 配置-虚拟站点、禁止IP访问
- Apache环境下Web站点禁止用服务器ip访问
- 配置apache禁止通过IP访问网站
- Apache禁止IP访问
- 禁止北京地区IP访问站点
- Apache 2.4 禁止通过IP地址访问
- 配置Apache的虚拟站点
- nginx 禁止某个IP访问站点
- nginx 禁止某个IP访问站点
- Apache禁止ip访问网站,禁止ip访问规则下载
- apache 设置IP访问、配置apache虚拟域名、Apache 配置二级域名、php 配置 curl
- 局域网访问Apache多个虚拟站点
- ubuntu配置虚拟ip
- APACHE 配置 虚拟站点和网站代理
- php 用apache配置虚拟站点
- Apache 本地配置多个虚拟站点
- apache禁止通过IP访问本机
- apache和nginx禁止IP地址访问
- Dx9安装失败 错误码S1023
- js 显示 当前时间 和星期
- [USACO4.2]草地排水(网络流最大流模板)
- JQuery点击事件优化
- Java并发之CyclicBarrier
- Ubuntu Apache 2.4 配置-虚拟站点、禁止IP访问
- Linux 常用基本命令 查看帮助文档
- Leetcode Reorder List
- 算法系列—— Implement Queue using Stacks
- mx51的三个framebuffer,mxc_ipuv3_fb.c分析
- 大数乘法
- Java编程思想初始化与清理
- 怎么用js模拟键盘ctrl+p
- java工具类(比如一个key对应value)