centos下利用httpd搭建http服務器方法


centos下利用httpd搭建http服務器方法

1. 解決的問題

在開發測試過程中,分析圖片任務需要將圖片保存在服務器端,通過url來訪問和下載該圖片,這就需要使用一台圖片服務器,但常常遇到圖片服務器匱乏的情況,為了解決該問題,可以臨時在自己電腦上搭建一個簡易的圖片服務器以供使用。本文給出了一種在centos系統上利用httpd搭建簡易圖片服務器的方法。

2. 搭建步驟

1)安裝httpd服務
在centos操作系統下執行shell命令:

yum install httpd -y

安裝完成后,可通過命令whereis httpd查看安裝位置

[root@localhost ld]# whereis httpd
httpd: /usr/sbin/httpd /usr/lib64/httpd /etc/httpd /usr/share/httpd /usr/share/man/man8/httpd.8.gz

rpm -qi httpd命令查看httpd的版本信息

[root@localhost ld]# rpm -qi httpd
Name        : httpd
Version     : 2.4.6
Release     : 80.el7.centos.1
Architecture: x86_64
Install Date: Mon 27 Aug 2018 02:10:31 PM CST
Group       : System Environment/Daemons
Size        : 9817285
License     : ASL 2.0
Signature   : RSA/SHA256, Tue 03 Jul 2018 10:31:55 PM CST, Key ID 24c6a8a7f4a80eb5
Source RPM  : httpd-2.4.6-80.el7.centos.1.src.rpm
Build Date  : Wed 27 Jun 2018 09:50:38 PM CST
Build Host  : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://httpd.apache.org/
Summary     : Apache HTTP Server
Description :
The Apache HTTP Server is a powerful, efficient, and extensible
web server.

2)啟動http服務
執行shell命令:

systemctl start httpd.service

3)配置文件說明
配置文件為/etc/httpd/conf/ httpd.conf,有幾個重要的參數需要配置:
① 端口
Listen參數,默認值為80,但為了避免和其他程序沖突,修改為其他值。

② 靜態文件的根目錄

DocumentRoot參數是需要生成url的文件存放路徑。

4)測試
在瀏覽器輸入http://服務器IP:port,看是否能進入HTTP樣本網頁,如果能進入如下頁面,說明httpd服務器搭建成功。

5)上傳圖片
將需要生成url的圖片上傳到DocumentRoot指定的目錄,即可在瀏覽器中訪問和下載該圖片。如保存lena.png圖片在DocumentRoot指定的目錄下,瀏覽器中輸入http://10.66.91.11:7777/lena.png即可訪問和下載該圖片。

  1. 總結
    通過在centos中利用httpd服務搭建簡易的圖片服務器,即可將任意一個待分析的圖片保存到指定目錄后通過url進行圖片的訪問和下載分析。

  2. 參考
    1)Permission denied: make_sock: could not bind to address
    https://blog.csdn.net/ljm_503909378/article/details/41244659

2) using localhost.localdomain for ServerName
https://www.cnblogs.com/52linux/archive/2012/03/24/2415637.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM