教你使用Apache搭建Http下载服务器
发布时间:2023-02-17 12:56:56 所属栏目:Apache 来源:互联网
导读:这篇文章主要介绍了使用Apache搭建Http下载服务器的详细过程,Apache2默认采用的是80端口号,因此直接通过公网ip或域名就能访问,需要的朋友可以参考下 前言 前段时间因为某些原因,几大主流网盘都无法使用,正好手头上有台闲置的云服务器,于是就想来搭建一
这篇文章主要介绍了使用Apache搭建Http下载服务器的详细过程,Apache2默认采用的是80端口号,因此直接通过公网ip或域名就能访问,需要的朋友可以参考下 前言 前段时间因为某些原因,几大主流网盘都无法使用,正好手头上有台闲置的云服务器,于是就想来搭建一个文件下载服务,用户只需通过一个链接就能下载软件。 Apache快速上手 经过调研,发现Ubuntu采用Apache2这个软件就可以快速满足我的需求。 安装Apache2 apt-get install apache2 安装好之后,启动Apache2服务: /etc/init.d/apache2 start 查看启动状态: /etc/init.d/apache2 status 然后,访问服务器的公网ip或域名,就可以看到如下界面,此时说明Apache正常工作: 在这里插入图片描述 最后在/var/www/html路径下,删除index.html,上传自己想要被下载的文件,再次访问,就可以进行下载了。 (注:如果是云服务器,还需要在安全组开放80和443端口号) 同时,也可以通过域名/文件名的方式直接给别人一个链接,进行下载。 在这里插入图片描述 如果有一台单独的服务器用于临时文件的分享,这样很快就搞定了。 下面来继续进行深入研究,考虑更现实的场景。 修改端口号 Apache2默认采用的是80端口号,因此直接通过公网ip或域名就能访问。现实中,很多服务器本身就部署了许多其它服务,80端口号往往被占用,因此就需要将Apache2改成其它访问端口。 修改端口,首先需要修改/etc/apache2/ports.conf这个文件: 这里吧80改成其它不冲突的端口号,我这里以1024为例 #Listen 80 Listen 1024 <IfModule ssl_module> Listen 443 </IfModule> <IfModule mod_gnutls.c> Listen 443 </IfModule> 然后修改/etc/apache2/sites-available/000-default.conf 1 2 3 4 #<VirtualHost *:80> <VirtualHost *:1024> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating 注:这个文件中还有一个DocumentRoot,修改该参数可以调整文件系统的根路径。 修改完成之后,重启apache2: 1 /etc/init.d/apache2 restart 此时,就可以通过访问域名:1024的形式访问到同样内容,例如我的服务器访问url为http://xdxsb.top:1024 设置访问限制 个人服务器很容易遭到别人的攻击,如果有人开好多线程来反复请求下载,这就将导致流量带宽消耗巨大,甚至会让服务器宕机。因此,长期提供下载服务的服务器必须设置访问限制。 配置文件参数详解 访问限制主要涉及到/etc/apache2/apache2.conf这个配置文件,首先来对该文件进行解读。 这个文件内容如下: # This is the main Apache server configuration file. It contains the # configuration directives that give the server its instructions. # See http://httpd.apache.org/docs/2.4/ for detailed information about # the directives and /usr/share/doc/apache2/README.Debian about Debian specific # hints. # # # Summary of how the Apache 2 configuration works in Debian: # The Apache 2 web server configuration in Debian is quite different to # upstream's suggested way to configure the web server. This is because Debian's # default Apache2 installation attempts to make adding and removing modules, # virtual hosts, and extra configuration directives as flexible as possible, in # order to make automating the changes and administering the server as easy as # possible. # It is split into several files forming the configuration hierarchy outlined # below, all located in the /etc/apache2/ directory: # # /etc/apache2/ # |-- apache2.conf # | `-- ports.conf # |-- mods-enabled # | |-- *.load # | `-- *.conf # |-- conf-enabled # | `-- *.conf # `-- sites-enabled # `-- *.conf # # # * apache2.conf is the main configuration file (this file). It puts the pieces # together by including all remaining configuration files when starting up the # web server. # # * ports.conf is always included from the main configuration file. It is # supposed to determine listening ports for incoming connections which can be # customized anytime. # # * Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/ # directories contain particular configuration snippets which manage modules, # global configuration fragments, or virtual host configurations, # respectively. # # They are activated by symlinking available configuration files from their # respective *-available/ counterparts. These should be managed by using our # helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See # their respective man pages for detailed information. # # * The binary is called apache2. Due to the use of environment variables, in # the default configuration, apache2 needs to be started/stopped with # /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not # work with the default configuration. # Global configuration # # # ServerRoot: The top of the directory tree under which the server's # configuration, error, and log files are kept. # # NOTE! If you intend to place this on an NFS (or otherwise network) # mounted filesystem then please read the Mutex documentation (available # at <URL:http://httpd.apache.org/docs/2.4/mod/core.html#mutex>); # you will save yourself a lot of trouble. # # Do NOT add a slash at the end of the directory path. # #ServerRoot "/etc/apache2" # # The accept serialization lock file MUST BE STORED ON A LOCAL DISK. # #Mutex file:${APACHE_LOCK_DIR} default # # The directory where shm and other runtime files will be stored. # DefaultRuntimeDir ${APACHE_RUN_DIR} # # PidFile: The file in which the server should record its process # identification number when it starts. # This needs to be set in /etc/apache2/envvars # PidFile ${APACHE_PID_FILE} # # Timeout: The number of seconds before receives and sends time out. # Timeout 300 # # KeepAlive: Whether or not to allow persistent connections (more than # one request per connection). Set to "Off" to deactivate. # KeepAlive On # # MaxKeepAliveRequests: The maximum number of requests to allow # during a persistent connection. Set to 0 to allow an unlimited amount. # We recommend you leave this number high, for maximum performance. (编辑:莱芜站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |