一、下载Apache Http Sever 2.4

(1)https://httpd.apache.org/download.cgi#apache24

Windows 下搭建 Apache Http Server 文件系统(详细)

Windows 下搭建 Apache Http Server 文件系统(详细)

(2)在 Apache 2.4 server binaries 栏选择 合适版本进行下载

Windows 下搭建 Apache Http Server 文件系统(详细)

 

二、安装与配置Apache Http Sever 2.4

(1)解压压缩包,得到下图所示的文件。一个是安装说明readme_first.html,一个是Apache24的文件夹。

(2)修改配置F:\Apache24\conf\httpd.conf

  • 指定 Apache24根目录为F:\Apache24

  • 修改监听端口 为8080,默认是80端口

  • 修改文件存放路径 ,默认就是 F:\Apache24\htdocs 目录

Define SRVROOT "F:\Apache24" ServerRoot "${SRVROOT}"

Listen 8080

//这里可以修改默认文件存放路径

DocumentRoot "${SRVROOT}/htdocs"<Directory "${SRVROOT}/htdocs">

(3)执行安装命令

httpd.exe -k install -n "Apache24" 

三 、启动Apache Http Server

方式一:通过命令行启动

通过如下命令可以开启和关闭Apache24服务:

httpd.exe -k start -n "Apache24"
httpd.exe -k stop -n "Apache24"

附: 重启和卸载http的命令

httpd.exe -k restart -n "Apache24"
httpd.exe -k uninstall -n "Apache24"

方式二:通过ApacheMonitor启动

双击/bin目录下的ApacheMonitor.exe,在笔者的电脑上,这个程序会最小化到托盘:

Windows 下搭建 Apache Http Server 文件系统(详细)

双击图标,即可图形化的方式运行:  

Windows 下搭建 Apache Http Server 文件系统(详细)

选中Apache24,可以start(启动)它,启动成功后,最小化到托盘的图标会变成绿色的三角形,说明已经成功启动。 

方式三:直接点击services.msc服务中的Apache24,启动或者停止服务

服务启动以后,可以在浏览器中输入http://localhost:8080,就可以查看到目录F:\Apache24\htdocs下的index.html文件。

在F:\Apache24\htdocs目录新建一个file 文件夹,然后放置一些文件,再次访问[http://localhost:8080/file 也是没问题的。

Windows 下搭建 Apache Http Server 文件系统(详细)

 

四、安装启动过程中可能出现的错误

(1)安装报错

Errors reported here must be corrected before the service can be started.(OS 10048)通常每个套接字地址(协议/网络地址/端口)只允许使用一次。 : AH00072: make_sock: could not bind to address [::]:443(OS 10048)通常每个套接字地址(协议/网络地址/端口)只允许使用一次。 : AH00072: make_sock: could not bind to address 0.0.0.0:443

说明443端口已经被占用

可用如下命令查看哪些 服务占用 了443端口

netstat -ano     
netstat -ano|findstr :443 

可以停掉 占用443端口的服务,或者修改F:\Apache24\conf\extra\httpd-ahssl.conf

打开F:\Apache24\conf目录下的httpd.conf,搜索ssl ,找到如下文字

# Secure (SSL/TLS) connections
# Note: The following must must be present to support
#       starting without SSL on platforms with no /dev/random equivalent
#       but a statically compiled-in mod_ssl.
#
<IfModule ssl_module>
#Include conf/extra/httpd-ssl.conf
Include conf/extra/httpd-ahssl.conf
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>

发现 ssl 443 端口 是配置 在 F:\Apache24\conf\extra\httpd-ahssl.conf 这个文件里面

将其中的443改成其他端口,如1443

第一处(Line 18) 、第二处(Line 134,136)、第三处(Line 150,152) 、 第四处(Line 165,167)的 443 全部改成 1443,

在用 管理员 再次执行 安装命令httpd.exe -k install -n "Apache24" 即可。

(2)解决启动Apache http server时报错(1053)

安装好http server后,一直无法启动服务,使用上述的方式一和方式二均未成功,而且不知道错误在哪里。使用方式三启动服务时,系统报错1053:服务没有及时响应启动或控制请求。

后来参考这个链接https://www.apachelounge.com/viewtopic.php?p=34728 ,估计自己也是因为没有安装最新的vc_redist.x64.exe。

到windows官网下载该程序,完成安装后,服务能正常启动了。

vc_redist.x64.exe的下载地址: https://www.microsoft.com/en-us/download/details.aspx?id=48145

 

五、设置 basic 用户认证

进入 F:\Apache24下的bin 目录

执行以下命令 创建 .htpasswd 文件,并添加 admin 用户 admin1用户

.\htpasswd.exe -bc F:\Apache24\conf.htpasswd admin 123456

.\htpasswd.exe -b F:\Apache24\conf.htpasswd admin1 123456

注意 : -c 参数 表示创建文件,-b表示将 用户信息追加到已经存在的文件中

Windows 下搭建 Apache Http Server 文件系统(详细)

(1)方式一,

  • 直接修改 F:\Apache24\conf\httpd.conf 的 <Directory "${SRVROOT}/htdocs">的标签里面内容

<Directory "${SRVROOT}/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/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks
​
    #
    # 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
      AllowOverride AuthConfig
      AuthType basic
      AuthName "allinone file server..."
      AuthUserFile F:/Apache24/conf/.htpasswd
      Require valid-user
    #
    # Controls who can get stuff from this server.
    #
    #Require all granted
</Directory>

 

重启apache http server

(2)方式二

在 F:\Apache24\htdocs 目录下创建.htaccess文件,并添加如下内容

AuthName "allinone file server..."
AuthType basic
AuthUserFile F:/Apache24/conf/.htpasswd
require valid-user

重启apache http server

再次访问 localhost:8080,弹出 用户验证窗口

Windows 下搭建 Apache Http Server 文件系统(详细)

 

 

 

 

相关文章: