教你使用Apache搭建Http

news2025/3/1 3:31:08

Apache2默认采用的是80端口号,因此直接通过公网ip或域名就能访问。现实中,很多服务器本身就部署了许多其它服务,80端口号往往被占用,因此就需要将Apache2改成其它访问端口。

修改端口,首先需要修改/etc/apache2/ports.conf这个文件:
这里吧80改成其它不冲突的端口号,我这里以1024为例

1
2
3
4
5
6
7
8

#Listen 80
Listen 1024

Listen 443

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.

MaxKeepAliveRequests 100

KeepAliveTimeout: Number of seconds to wait for the next request from the

same client on the same connection.

KeepAliveTimeout 5

These need to be set in /etc/apache2/envvars

User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

HostnameLookups: Log the names of clients or just their IP addresses

e.g., www.apache.org (on) or 204.62.129.132 (off).

The default is off because it’d be overall better for the net if people

had to knowingly turn this feature on, since enabling it means that

each client request will result in AT LEAST one lookup request to the

nameserver.

HostnameLookups Off

ErrorLog: The location of the error log file.

If you do not specify an ErrorLog directive within a

container, error messages relating to that virtual host will be

logged here. If you do define an error logfile for a

container, that host’s errors will be logged there and not here.

ErrorLog ${APACHE_LOG_DIR}/error.log

LogLevel: Control the severity of messages logged to the error_log.

Available values: trace8, …, trace1, debug, info, notice, warn,

error, crit, alert, emerg.

It is also possible to configure the log level for particular modules, e.g.

“LogLevel info ssl:warn”

LogLevel warn

Include module configuration:

IncludeOptional mods-enabled/.load
IncludeOptional mods-enabled/
.conf

Include list of ports to listen on

Include ports.conf

Sets the default security model of the Apache2 HTTPD server. It does

not allow access to the root filesystem outside of /usr/share and /var/www.

The former is used by web applications packaged in Debian,

the latter may be used for local directories served by the web server. If

your system is serving content from a sub-directory in /srv you must allow

access here, or in any related virtual host.

Options FollowSymLinks AllowOverride None Require all denied

参数解释:

PidFile:记录服务器启动进程号的文件

Timeout:接收和发送前超时秒数

KeepAlive:是否允许稳固的连接(每个连接有多个请求),设为"Off"则停用

MaxKeepAliveRequests:在稳固连接期间允许的最大请求数,设为0表示无限制接入

KeepAliveTimeout:在同一个连接上从同一台客户上接收请求的秒数

User/Group:运行的用户和组

HostnameLookups:指定记录用户端的名字还是IP地址
例如,本指令为on时记录主机名,如www.apache.org;为off时记录IP地址,204.62.129.132。默认值为off,这要比设为on好得多,因为如果设为on则每个用户端请求都将会至少造成对 nameserver 进行一次查询。

ErrorLog:错误日志文件定位

LogLevel:控制记录在错误日志文件中的日志信息
可选值:debug,info,notice,warn,error,crit,alert,emerg

Directory:在标签对里面可以设置各文件夹属性

Options:控制在特定目录中将使用哪些服务器特性

All:除MultiViews之外的所有特性,这是默认设置
ExecCG:允许使用mod_cgi执行CGI脚本
FollowSymLinks:服务器允许在此目录中使用符号连接,如果此配置位于配置段中,则会被忽略
Includes:允许使用mod_include提供的服务器端包含
IncludesNOEXEC:允许服务器端包含,但禁用"#exec cmd"和"#exec cgi",但仍可以从ScriptAlias目录使用"#include virtual"虚拟CGI脚本
Indexes:如果一个映射到目录的URL被请求,而此目录中又没有DirectoryIndex(例如:index.html),那么服务器会返回由mod_autoindex生成的一个格式化后的目录列表
MultiViews:允许使用mod_negotiation提供内容协商的"多重视图"(MultiViews)
SymLinksIfOwnerMatch:服务器仅在符号连接与其目的目录或文件的拥有者具有相同的uid时才使用它。 如果此配置出现在配置段中,则将被忽略
AllowOverride:确定允许存在于.htaccess文件中的指令类型
语法:AllowOverride All|None|directive-type [directive-type]
如果此指令被设置为None ,那么.htaccess文件将被完全忽略。
directive-type可以是下列各组指令之一:

AuthConfig : 允许使用与认证授权相关的指令
FileInfo : 允许使用控制文档类型的指令、控制文档元数据的指令、mod_rewrite中的指令、mod_actions中的Action指令
Indexes : 允许使用控制目录索引的指令
Limit : 允许使用控制主机访问的指令
Order:控制默认的访问状态与Allow和Deny指令生效的顺序

Deny,Allow : Deny指令在Allow指令之前被评估。默认允许所有访问。任何不匹配Deny指令或者匹配Allow指令的客户都被允许访问
Allow,Deny : Allow指令在Deny指令之前被评估。默认拒绝所有访问。任何不匹配Allow指令或者匹配Deny指令的客户都将被禁止访问
Mutual-failure : 只有出现在Allow列表并且不出现在Deny列表中的主机才被允许访问。这种顺序与"Order Allow,Deny"具有同样效果
Allow:控制哪些主机可以访问服务器的该区域。可以根据主机名、IP地址、 IP地址范围或其他环境变量中捕获的客户端请求特性进行控制。
语法:Allow from all|host|env=env-variable [host|env=env-variable]

Deny:控制哪些主机被禁止访问服务器的该区域。可以根据主机名、IP地址、 IP地址范围或其他环境变量中捕获的客户端请求特性进行控制。
语法:Deny from all|host|env=env-variable [host|env=env-variable]

Require:访问限制

  • all granted:表示允许所有主机访问
  • all denied:表示拒绝所有主机访问
  • local:表示仅允许本地主机访问
  • [not] host <主机名或域名列表>:表示允许或拒绝指定主机或域名访问
  • [not] ip <IP地址或网段列表>:表示允许或拒绝指定的IP地址或网段访问

AccessFileName:设置分布式配置文件的名字,默认为.htaccess
如果为某个目录启用了分布式配置文件功能,那么在向客户端返回其中的文档时,服务器将在这个文档所在的各级目录中查找此配置文件

<FilesMatch"^.ht">:拒绝对.ht开头文件的访问,以保护.htaccess文件

LogFormat:定义访问日志的格式

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/426517.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

数组排序详解

数组排序详解1、排序算法小结2、排序算法原理及实现2.1 归并排序2.2 快速排序2.3 冒泡排序2.4 插入排序2.5 选择排序2.6 希尔排序&#xff1a;1、排序算法小结 排序算法可以分为两大类&#xff1a; &#xff08;1&#xff09;非线性时间排序算法&#xff1a;通过比较来决定元素…

用Python实现批量翻译文档文件

文件名批量翻译需要用到编程语言和相应的翻译 API&#xff0c;下面以 Python 和 Google 翻译 API 为例&#xff0c;介绍具体的实现步骤&#xff1a; 安装必要的 Python 库 使用 Python 代码进行文件名翻译需要先安装两个库&#xff1a;googletrans 和 os。 pip install googl…

全网最全的Cookie, Session, Token鉴权详解,一定让你大饱眼福

目录 前言 一、Cookie鉴权 二、Session鉴权 ​编辑 三、Token鉴权 四、总结 前言 在Web开发中&#xff0c;鉴权是保护用户数据和系统安全的重要手段之一。常见的鉴权方式包括Cookie、Session和Token三种&#xff0c;下面我将详细介绍这三种鉴权方式&#xff0c;并且探讨它…

FMC子卡设计资料:ADRV9002双窄带宽带射频收发器 AD9361双收双发射频 DA子卡 ADRV9009双收双发射频FMC子卡

FMC550-基于ADRV9002双窄带宽带射频收发器FMC子卡 一、产品概述 ADRV9002 是一款高性能、高线性度、高动态范围收发器&#xff0c;旨在针对性能与功耗系统进行优化。该设备是可配置的&#xff0c;非常适合要求苛刻、低功耗、便携式和电池供电的设备。ADRV9002 的工作频率为…

基于典型相关分析的故障检测和过程监控算法研究(Matlab代码实现)

&#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5;&#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜密&#xff0c;逻辑清晰&#xff0c;为了方便读者。⛳座右铭&#…

分布式消息中间件概念

对于分布式消息中间件&#xff0c;首先要了解两个基础的概念&#xff0c;即什么是分布式系统&#xff0c;什么又是中间件。 分布式系统 “A distributed system is one in which components located at networked computers communicate and coordinate their actions only by …

Java 中常用的版本对应关系,springboot springcloud,cloud-alibaba

1.网址链接&官方文档链接 SpringCloud与SpringBoot的版本对应关系:https://start.spring.io/actuator/info SpringBoot版本列表&#xff1a;https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent SpringBoot最新GA版官方文档&#…

【计算机网络——制作双绞线】

文章目录实验目的:实验内容及过程记录&#xff08;一&#xff09;剪线&#xff08;二&#xff09;剥皮&#xff08;三&#xff09;排序&#xff08;四&#xff09;剪齐&#xff08;五&#xff09;插入&#xff08;六&#xff09;压制&#xff1a;&#xff08;七&#xff09;检测…

vscode debug Attach mode

Python Debug Mode: 常规debug。针对*.py python脚本启动的场景。 在使用vscode debug时&#xff0c;如果调试python脚本其实很简单。 .vscode/launch.json文件。 {"version": "0.2.0","configurations": [{"name": "Python: C…

7年经验,功能测试工程师该如何一步步提升自己的能力呢?

功能测试&#xff08;所谓“点点点”&#xff09;在行业中基本能拿到10k左右的薪水&#xff0c;但是你不可能一直点。入行3年后&#xff0c;你需要拥有不止点点点的技能&#xff0c;否则出去面试&#xff0c;你会就会感受到竞争者给你带来的压力&#xff0c;你需要拿出更高级的…

真题详解(Flynn分类)-软件设计(四十六)

真题详解&#xff08;计算机总线&#xff09;-软件设计&#xff08;四十五)https://blog.csdn.net/ke1ying/article/details/130046829 Flynn分类将计算机分为四类。 单指令流单数据流机器&#xff08;SISD&#xff09;&#xff1a;早期的机器&#xff0c;在某个时钟周期&…

C++中的输入输出流iostream、文件流fstream、字符串流sstream解释

文章目录前言流的理解流的优势C中流的分类IO流字符串流sstream基本概念使用文件流fstream文本文件写文件读文件前言 流的解释。 流的理解 流的本质是一种对象。 流是介于数据和程序之间的一个中转设备。 因为流的存在&#xff0c;使得我们可以不需要直接操作数据&#xff…

瑞吉外卖Linux

1、linux简介 Linux系统版本 Linux系统分为内核版和发行版 内核版&#xff1a; 由LinusTorvalds及其团队开发、维护 免费、开源 负责控制硬件 发行版&#xff1a; 基于Linux内核版进行扩展 由各个Linux厂商开发、维护 有收费…

自动插入匹配与标题相关的百度图片或者搜狗图片软件-批量插入txt文档-Chatgpt批量写文章配图神器

1、我们用《Chatgpt 3.5-turbo软件》批量生成txt文档&#xff0c;但是这样txt文档里不带图片&#xff0c;直接发布到网站上&#xff0c;光有文字没有图片&#xff0c;效果也不是很理想&#xff0c;就需要一款配图软件。 2、该软件根据txt标题自动匹配百度图片或者搜狗图片里的…

Redis高可用

最近离职后还没开始找工作&#xff0c;在找工作前去学习一下Redis高可用方案。 目录Redis高可用高可用的概念实现方式持久化主从复制简单结构优化结构优缺点哨兵模式&#xff08;Sentinel&#xff09;哨兵进程的作用自动故障迁移(Automatic failover)优缺点集群优缺点Redis高可…

300左右买什么蓝牙耳机好?300元内音质最好的蓝牙耳机

在市场上有很多蓝牙耳机。当时无线蓝牙耳机如此流行也是由苹果公司提出。作为首次取消手机上3.5毫米耳机插孔的手机&#xff0c;后面许多手机也纷纷效仿。但这也促进了科学技术的发展。下面分享几款300元内音质表现不错的蓝牙耳机。 第一款&#xff1a;南卡小音舱Lite2蓝牙耳机…

【深度思考】人工智能技术对未来各行业的影响,我们该如何应对?

目录 1、AI的应用对行业带来的机遇 2、AI将冲击哪些行业 3、如何应对AI对个人发展的挑战 4、AI对于程序员的冲击 随着技术的不断发展&#xff0c;AI已经开始深刻影响着各行各业。从生产制造到金融、医疗和交通等行业&#xff0c;人工智能技术都在发挥着越来越重要的作用。现…

ijkplayer编译支持x264编码器

ijkplayer作为一款基于ffmpeg在移动端比较流行的播放器&#xff0c;并没有集成编码器。如果使用ffmpeg且需要音视频编码功能的话就需要自己手动集成。 编译支持x264编码器的流程主要参考了 ijkplayer支持x264编译 - 简书 原理与ijkplayer编译支持openssl的流程类似。 1 下载x…

项目管理 | 10年项目经理推荐的一份书单:你认真读过几本?

作为一名项目经理&#xff0c;我们需要在团队之间协调合作&#xff0c;管理预算和资源&#xff0c;确保项目按时、按预算顺利完成。因此&#xff0c;学习项目管理知识是提高我们的职业素养、职业技能和职业竞争力的关键。 今天就来给大家分享几本具有广泛影响力和权威性的项目…

如何动态的给一个类增加功能?

装饰器模式概述 装饰模式可以在不改变一个对象本身功能的基础上给对象增加额外的新行为&#xff0c;在现实生活中&#xff0c;这种情况也到处存在&#xff0c;例如一张照片&#xff0c;我们可以不改变照片本身&#xff0c;给它增加一个相框&#xff0c;使得它具有防潮的功能&a…