摘要
Linux提供了httpd服务,相当于一个文件下载服务,开启后可以通过wget方式下载服务器上的文件。
但是开启服务后,下载文件提示权限问题,导致下载失败。本篇文章记录开启过程和下载失败的原因。
开启httpd服务
httpd一般是系统自带的服务,只需要修改一些默认的配置项,然后使用systemctl开启即可。
httpd配置文件目录:
/etc/httpd/conf/httpd.conf
需要关注的配置项:
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 80
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/var/www/html"
第一个是监听端口,第二个是需要下载的文件根目录。
其他还有一些文件下载权限的配置,请查看配置文件中的解释。
开启服务:
systemctl start httpd
开启后则可以使用 wget http://ip:80/index.html 下载文件了。
问题1:服务开启失败
[root@linux-4-192 www]# systemctl status httpd.service
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since 四 2021-10-21 03:44:41 EDT; 3s ago
Docs: man:httpd(8)
man:apachectl(8)
Process: 12902 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
Main PID: 12902 (code=exited, status=1/FAILURE)
10月 21 03:44:41 linux-4-192 systemd[1]: Starting The Apache HTTP Server...
10月 21 03:44:41 linux-4-192 httpd[12902]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.24.4.192. Set the 'ServerName' directive globally to suppress this message
10月 21 03:44:41 linux-4-192 httpd[12902]: (13)Permission denied: AH00072: make_sock: could not bind to address 172.24.4.192:10080
10月 21 03:44:41 linux-4-192 httpd[12902]: no listening sockets available, shutting down
10月 21 03:44:41 linux-4-192 httpd[12902]: AH00015: Unable to open logs
10月 21 03:44:41 linux-4-192 systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
10月 21 03:44:41 linux-4-192 systemd[1]: Failed to start The Apache HTTP Server.
10月 21 03:44:41 linux-4-192 systemd[1]: Unit httpd.service entered failed state.
10月 21 03:44:41 linux-4-192 systemd[1]: httpd.service failed.
[root@linux-4-192 www]#
由于安全问题,httpd一般只允许使用默认的几个服务端口,如果使用其他端口则服务启动失败。
允许使用的服务端口包含:
80, 81, 443, 488, 8008, 8009, 8443, 9000
问题2:服务开启后,文件下载失败
下载文件时提示403。
这种一般是需要下载的文件没有执行权限,所以要通过chmod赋予775的权限。