Ubuntu Server下XAMPP建站的初级安全设置

欢迎使用xampp

xampp是新手建站的绝佳利器,但正如xampp部署成功页面所说

XAMPP is meant only for development purposes. It has certain configuration settings that make it easy to develop locally but that are insecure if you want to have your installation accessible to others. If you want have your XAMPP accessible from the internet, make sure you understand the implications and you checked the FAQs to learn how to protect your site. Alternatively you can use WAMP, MAMP or LAMP which are similar packages which are more suitable for production.

在利用xampp在互联网建站前我们需要做一些基础的设置来确保网站的安全

首先我们先要找到xampp的文件安装地址
在ubuntu上,xampp默认叫LAMPP因为是Linux + Apache + MariaDB + PHP + Perl

另外,xampp软件以前的名字也叫lampp。因为和lampp环境名称混淆了,后来xlampp软件改名为现在的xampp。lamp和xampp和lampp的区别

我的腾讯云服务器用的是ubuntu server默认是不带ui界面的,当然可以自己安装Gnome通过腾讯云官方的VNC打开GUI的桌面,但分辨率不可调,窗口很小,很伤眼睛,所以还是推荐学习一下Terminal使用方法(建议在腾讯云实验室里自行进行linux操作实验),正所谓“工欲善其事,必先利其器”嘛

在部署过xampp后(我还是用GUI在官网下载的,但速度奇慢无比)
其默认安装地址在 /opt/lampp/

我们利用MacOS自带命令行Terminal.app进行下面的操作,因为刚用上Mac,要好好利用现有的资源

基本操作

首先还是要先看看官方的FaQ,点击部署成功页面的FAQ可以查看基础的信息

最基本的是这两个吧
输入sudo opt/lampp/lampp start可在命令行开启apache和mySql服务
输入sudo opt/almpp/lampp stop可在命令行关闭apache和mySql服务

1.修改默认的账户密码

为什么默认配置不安全呢,官方解释

Here a list of missing security in XAMPP:
The MySQL administrator (root) has no password.
The MySQL daemon is accessible via network.
ProFTPD uses the password “lampp” for user “daemon”.

在FAQ页面可以看到这个
在打开xampp后,输入 sudo /opt/lampp/lampp security
xampp将会对整个系统进行安全检查,要求你设置账户和密码以提高安全性

2.隐藏Apache的版本信息

apache2的默认配置文件有两个,
一个在apache2/conf/httpd.conf
一个在etc/httpd.conf

利用cd 命令转到配置目录
利用sudo vim httpd.conf命令打开httpd.conf文件进行编辑
输入i进入vim 的INSERT模式

注:vim是linux命令行下的一个自带文本编辑器,同样MacOS也自带,利用这个可以实现记事本的功能,从而不必进入VNC的GUI操作,节省时间,具体vim的操作可以参考此处 讲述的很详细

在文末输入

#hide apache version to protect website
ServerTokens Prod
ServerSignature Off 

按下esc退出编辑模式
输入:wq 按下enter(回车)

即可保存
这样可避免显示服务器的版本信息

Apache/2.2.8 (Win32) DAV/2 mod_ssl/2.2.8 OpenSSL/0.9.8g mod_autoindex_color PHP/5.2.5 mod_jk/1.2.25

3.禁止apache目录索引功能

etc/httpd.conf文件中找到option的位置

cd etc/
sudo vim httpd.conf

找到option 类似于

<Directory "/Applications/XAMPP/xamppfiles/htdocs/">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/trunk/mod/core.html#options
    # for more information.
    #
    #Options Indexes FollowSymLinks
    # XAMPP
    Options Indexes FollowSymLinks ExecCGI Includes

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    #AllowOverride None
    # since XAMPP 1.4:
    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

将其中的Options Indexes FollowSymLinks ExecCGI Includes中的 Indexes删除
之后重启apache服务,索引功能就会被关闭

4.php安全配置

1.启用安全模式

etc目录下,找到php.ini的配置文件,找到:

safe_mode = Off //改为On

2.必须禁用一些高危函数,其中,可以保留phpinfo这个函数

disable_functions = exec,passthru,shell_exec,system,popen,proc_open,proc_close,curl_exec,curl_multi_exec,par se_ini_file,show_source,dl,passthru,escapeshellarg,escapeshellcmd

3.禁止显示PHP的版本

expose_php = Off
最后,对于mysql的备份,我们可以通过批处理脚本配置合计划任务进行备份。也可以通过工具的实现计划备份,如官方的工具MySQL Administrator,找到back项,通过Schedule选项卡生成备份任务,通过计划任务进行调度。

参考资料

xampp安全配置
apache在默认404、403提示页面中隐藏apache版本和系统信息
如何隐藏 Apache 版本号和其它敏感信息
如何在 HTTP 头中隐藏 PHP 版本号
linux/mac vi命令详解

猜你喜欢

转载自blog.csdn.net/xzy565143480/article/details/83038567