日期:2014-05-16  浏览次数:20821 次

Linux: Apache 安全设定

1. AutoIndex

?

预设安装好 Apache 之后,其预设目录是在 /var/www/html/,如果没有设定 index.html 的话,那么就会印出目前目录里的所有档案和目录,基於安全理由,希望把 AutoIndex 这个取消,如此在别人打入网址后,就会出现 403 的存取权限不足,只有在很“明确”的指出档案时才可以浏览。

?

关闭 /var/www/html 里(含子目录)的自动印出首页功能

[root@rhel conf]# vi httpd.conf
_______________________________
<Directory "/var/www/html">
#把 Options Indexes FollowSymLinks 注解起来
#Options Indexes FollowSymLinks
#修改成只剩 FollowSymLinks
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
_______________________________
[root@rhel conf]#

?

注意:

如果你是从Windows转过来Ubuntu的话,可能都会有一个疑问,为什么在Ubuntu上找不到httpd.conf档哩?? 因为Ubuntu上根本就不用httpd.conf这个名称了。

?

在装好Apache2之后,Apache2的设定档会存放在 /etc/apache2,里面有一个apache2.conf档是整个Apache2的设定 档,一般来说是不用去动它的,如果要调设定的话,是要到/etc/apache2/sites-available里去调的,预设的网站是调/etc /apache2/sites-available/default这个档的,而这个档就等同是httpd.conf,只是命名方式不同而已哩!!

?

/etc/apache2/sites-available和/etc/apache2/sites-enabled有什么不同?没有不同,只要是在sites-available有用a2ensite指令启用的虚拟主机,就会在sites-enabled建立一个连结。

?

重新启动 httpd

[root@rhel conf]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@rhel conf]#

?

或者:

// Apache
//Task: Start Apache 2 Server /启动apache服务
# /etc/init.d/apache2 start
//or
$ sudo /etc/init.d/apache2 start
//Task: Restart Apache 2 Server /重启apache服务
# /etc/init.d/apache2 restart
//or
$ sudo /etc/init.d/apache2 restart
//Task: Stop Apache 2 Server /停止apache服务
# /etc/init.d/apache2 stop
//or
$ sudo /etc/init.d/apache2 stop 
// Mysql
/etc/init.d/mysql start
/etc/init.d/mysql stop
/etc/init.d/mysql restart

?

// httpd是Apache超文本传输协议(HTTP)服务器的主程序。被设计为一个独立运行的后台进程,它会建立一个处理请求的子进程或线程的池。
// 通常,httpd不应该被直接调用,而应该在类Unix系统中由 apachectl 调用
// man apache2 中介绍
// apache2 is the Apache HyperText Transfer Protocol (HTTP) server program.
// It is designed to be run as a standalone daemon process. When  used  like
// this it will create a pool of child processes or threads to handle requests.
// In general, apache2 should not be invoked directly,
// but rather should be invoked via /etc/init.d/apache2 or apache2ctl.
// The default Debian config-uration requires environment variables
// that are defined in /etc/apache2/envvars and are not available if apache2 is  started  directly.
// However,apache2ctl can be used to pass arbitrary arguments to apache2.
//
// apache2ctl = apache2 ConTroL
//
apache2ctl -restart
apache2ctl -stop
apache2ctl -t
// 详细见 man apache2

?

2. 虚拟目录

?

一般特别重要或有特别作用的目录,会放在 /var/www/html 之外的其它目录,比方说现在 /file/download/ 目录,要在使用者打入 http://www.abc.com.tw/download/ 时,可以自动对应到 /file/download/ 这个目录,就好像是在 /var/www/html 里面一样,这时我们可以使用 alias 的方式做出一个虚拟目录,使用 Alias 就可以办得到了。

[root@rhel conf]# vi httpd.conf
_______________________________
Alias /download/ "/file/download/"
_______________________________
[root@rhel conf]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@rhel conf]#

?

注意:Alias 语法为 Alias {target} {source},在 {target} 的描述中(以 download),如果打了一个 "/" 符号,那么使用者在输入网址时只能是 http://www.abc.com.tw/download/ 后面就要多带一个 "/",否则会出现 404 的找不到档案错误。

?

3. ServerName 的设定

友情链接: 爱易网 云虚拟主机技术 云服务器技术 程序设计技术 开发网站 APP开发教程
Copyright © 2013-2024 爱易网页 当前在线:772人  网站在2时3分20秒内访问总人数:31870人 当前 90.54%  粤ICP备18100884号-2