使用Apache搭建http服務(wù)器實現(xiàn)CGI功能
一、環(huán)境搭建
搭建環(huán)境CentOS7.5.
專門處理 HTTP 請求的服務(wù)器,也被稱為 Web 服務(wù)器。 常用的 Web 服務(wù)器有 Apache和 Nginx ,當(dāng)然幾大巨頭五聯(lián)網(wǎng)公司也都有其獨自研發(fā)的 Web 服務(wù)器,比如阿里巴巴的Tengine 。 我們使用 Apache 作為 Web 服務(wù)器,并按照下面 5 個步驟安裝好 Apache 。
1、下載安裝包
安裝lynx命令,是一種以文本方式查看網(wǎng)頁的工具,當(dāng)然你也可以選擇直接百度下載
參考:https://blog.csdn.net/u011641885/article/details/45459199
lynx http://httpd.apache.org/download.cg
我下載的是2.4.54版本。
2、安裝依賴包
解壓,進入解壓目錄,
gzip -d httpd- 2.4.54.tar.gz tar xvf httpd-2.4.54.tar cd httpd-2.4.54
這時候直接是安裝不了的,需要依賴包
(1)下載相關(guān)包
gzip -d httpd- 2.4.54.tar.gz tar xvf httpd-2.4.54.tar cd httpd-2.4.54
(2)解決apr not found
tar -zxf apr-1.4.5.tar.gz cd apr-1.4.5 ./configure --prefix=/usr/local/apr make make install
(3)解決APR-util not found
tar -zxf apr-util-1.3.12.tar.gz cd apr-util-1.3.12 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config --enable-utf8 make make install
(4)解決pcre問題
unzip -o pcre-8.10.zip cd pcre-8.10 ./configure --prefix=/usr/local/pcre make && make install
安裝完所有依賴包之后執(zhí)行
./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre/bin/pcre-config
接下來執(zhí)行
makemake install
3、修改配置文件
vi /usr/local/apache/conf/httpd.conf
打開該行注釋
#ServerName www.example.com:80
4、啟動服務(wù)
/usr/local/apache/bin/apachectl start
停止服務(wù)
/usr/local/apache/bin/apachectl stop
重啟服務(wù)
/usr/local/apache/bin/apachectl restart
5、測試
在你的瀏覽器輸入你的機器的IP地址,就是你配置apache的機器IP,提示以下代表安裝成功。
二、測試CGI
1、修改配置文件
vi /usr/local/apache/conf/httpd.conf
打開該行注釋,開啟模塊
#LoadModule cgid_module modules/mod_cgid.so #LoadModule alias_module modules/mod_alias.so
2、重啟服務(wù)
/usr/local/apache/bin/apachectl restart
3、創(chuàng)建CGI腳本
在/usr/local/apache/cgi-bin/ 目錄下創(chuàng)建cgiscript腳本,腳本內(nèi)容如下:
#include <iostream> using namespace std; int main (){ cout << "Content-type:text/html\r\n\r\n"; cout << "<html>\n"; cout << "<head>\n"; cout << "<title>Hello World - First CGI Program</title>\n"; cout << "</head>\n"; cout << "<body>\n"; cout << "<h2>Hello World! This is my first CGI program</h2>\n"; cout << "</body>\n"; cout << "</html>\n"; return 0; }
g++ -o test cgiscript
4、瀏覽器測試
在瀏覽器中輸入以下內(nèi)容:
http://192.168.122.1/cgi-bin/test
到此這篇關(guān)于使用Apache搭建http服務(wù)器,實現(xiàn)CGI的文章就介紹到這了,更多相關(guān)Apache http服務(wù)器內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 教你使用Apache搭建Http下載服務(wù)器
- centos8使用Apache httpd2.4.37安裝web服務(wù)器的步驟詳解
- 阿里云服務(wù)器apache配置SSL證書成功開啟Https(記錄趟過的各種坑)
- 使用Apache打造完美限制的HTTP下載服務(wù)器
- 詳解為新版Apache服務(wù)器開啟HTTP/2支持的方法
- Linux下SVN服務(wù)器同時支持Apache的http和svnserve獨立服務(wù)器兩種模式且使用相同的訪問權(quán)限賬號
- Apache服務(wù)器主配置文件httpd.conf詳解
- 分享apache http服務(wù)器設(shè)置虛擬主機的方法
相關(guān)文章
CentOS7 安裝 zabbix 4.0 教程(圖文詳解)
這篇文章主要介紹了CentOS7 安裝 zabbix 4.0 教程,本文圖文并茂給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-10-10linux環(huán)境下設(shè)置shadowsocks+polipo全局代理
XX-NET僅僅可以是用戶通過瀏覽器訪問外面世界,而非系統(tǒng)全局代理,使用shadowsocks+polipo技術(shù)可使功能進一步拓展2018-09-09Linux使用less高效讀取GC日志的實現(xiàn)方法
在Linux環(huán)境中,日志分析是運維和開發(fā)人員日常工作中不可或缺的一部分,特別是對于Java應(yīng)用的垃圾回收(GC)日志,本文將結(jié)合實際案例,詳細講解如何使用 less 命令高效讀取和分析GC日志,需要的朋友可以參考下2025-04-04