apache安裝

apache安裝

軟件下載

apache httpd

http://httpd.apache.org/download.cgi

APR 和 APR-Util

http://apr.apache.org/download.cgi

PCRE

https://sourceforge.net/projects/pcre/files/pcre/

軟件版本列表

  • httpd-2.4.37
  • apr-1.6.5
  • apr-util-1.6.1
  • pcre-8.42

軟件安裝

上傳文件至安裝目錄

此處選用/usr/local/soft

解壓文件

tar -xzf /usr/local/soft/apr-1.6.5.tar.gz -C /usr/local/
tar -xzf /usr/local/soft/apr-util-1.6.1.tar.gz -C /usr/local/
tar -xzf /usr/local/soft/pcre-8.42.tar.gz -C /usr/local/
tar -xzf /usr/local/soft/httpd-2.4.37.tar.gz -C /usr/local/

創建安裝目錄

mkdir /usr/local/apr
mkdir /usr/local/apr-util
mkdir /usr/local/pcre
mkdir /usr/local/httpd

安裝編譯文件

  • apr
    cd /usr/local/apr-1.6.5
    ./configure --prefix=/usr/local/apr
    make
    make install
  • apr-util
    cd /usr/local/apr-util-1.6.1
    ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
    make
    make install
  • pcre
    cd /usr/local/pcre-8.42
    ./configure --prefix=/usr/local/pcre --with-apr=/usr/local/apr/bin/apr-1-config
    make
    make install
  • httpd
    cd /usr/local/httpd-2.4.37

./configure --prefix=/usr/local/httpd --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-ssl=/usr/local/openssl --enable-mods-shared=all --with-mpm=worker --enable-rewrite --enable-ssl
make
make install

環境配置

開啟對應端口
Listen 443
Listen 3129
Listen 3127

正向反向用

LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_module modules/mod_proxy.so

https用

LoadModule ssl_module modules/mod_ssl.so

rewrite用

LoadModule rewrite_module modules/mod_rewrite.so

  • 正向代理
<VirtualHost *:3129>
# ServerAdmin webmaster@jsoft.cn
ServerName 11.16.53.33
#ProxyPreserveHost On
#ProxyPass / https://api.mch.weixin.qq.com/
ProxyRequests On #正向代理
ProxyVia On #正向代理
#實驗結果:正向代理 Rewrite 不生效
#RewriteEngine On
#RewriteCond %{SERVER_PORT} ^3129$
#RewriteCond %{SERVER_PORT} !^443$
#RewriteCond %{SERVER_PORT} ^80$
#RewriteRule ^(.*)$ http://11.16.53.33:8001[L,P]
#RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
</VirtualHost>

  • 反向代理
    普通
<VirtualHost *:3127>
# ServerAdmin webmaster@jsoft.cn
ServerName 11.16.53.33
#實驗結果:反向代理 Rewrite 生效
RewriteEngine On #重寫地址(改變目標地址)時使用
#RewriteCond %{SERVER_PORT} ^3127$
RewriteRule ^(.*)$ https://11.16.53.33
#RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

#普通的跳轉時使用
ProxyPreserveHost On  
ProxyPass /test http://11.16.53.33:8000/
</VirtualHost>

https

<VirtualHost *:443>     # 必須有一個虛擬主機,這樣才可以使用跳轉功能和使用443端口訪問
SSLEngine on
SSLCertificateFile /usr/local/httpd/certs/server.crt
SSLCertificateKeyFile /usr/local/httpd/certs/server.key
#重寫地址(改變目標地址)時使用
RewriteEngine On
#RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*)$ https://www.baidu.com

#普通的跳轉時使用
ProxyPreserveHost On  
ProxyPass /test http://11.16.53.33:8000/
</VirtualHost>

安裝gcc
參考https://www.jb51.net/article/103633.htm
http://gcc.gnu.org/下載gcc安裝包 gcc-4.8.2.tar.gz
ftp://ftp.gnu.org/gnu/gmp/ 下載GMP安裝包 gmp-5.1.3 .tar.bz2
http://ftp.gnu.org/gnu/mpfr/ 下載MPFR安裝包 mpfr-3.1.2.tar.gz
http://www.cise.ufl.edu/mirrors/GNU/pub/gnu/mpc 下載MPC安裝包 mpc-1.0.1.tar.gz

附錄
錯誤1 安裝 apr-util

make[1]: Entering directory `/usr/local/apr-util-1.6.1'
/bin/sh /usr/local/apr/build-1/libtool --silent --mode=compile gcc -g -O2 -pthread   -DHAVE_CONFIG_H  -DLINUX -D_REENTRANT -D_GNU_SOURCE   -I/usr/local/apr-util-1.6.1/include -I/usr/local/apr-util-1.6.1/include/private  -I/usr/local/apr/include/apr-1    -o xml/apr_xml.lo -c xml/apr_xml.c && touch xml/apr_xml.lo
xml/apr_xml.c:35:19: error: expat.h: No such file or directory
xml/apr_xml.c:66: error: expected specifier-qualifier-list before ‘XML_Parser’
xml/apr_xml.c: In function ‘cleanup_parser’:
xml/apr_xml.c:364: error: ‘apr_xml_parser’ has no member named ‘xp’
xml/apr_xml.c:365: error: ‘apr_xml_parser’ has no member named ‘xp’
xml/apr_xml.c: At top level:
xml/apr_xml.c:384: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
xml/apr_xml.c: In function ‘apr_xml_parser_create’:
xml/apr_xml.c:401: error: ‘apr_xml_parser’ has no member named ‘xp’
xml/apr_xml.c:402: error: ‘apr_xml_parser’ has no member named ‘xp’
xml/apr_xml.c:410: error: ‘apr_xml_parser’ has no member named ‘xp’
xml/apr_xml.c:411: error: ‘apr_xml_parser’ has no member named ‘xp’
xml/apr_xml.c:412: error: ‘apr_xml_parser’ has no member named ‘xp’
xml/apr_xml.c:424: error: ‘apr_xml_parser’ has no member named ‘xp’
xml/apr_xml.c:424: error: ‘default_handler’ undeclared (first use in this function)
xml/apr_xml.c:424: error: (Each undeclared identifier is reported only once
xml/apr_xml.c:424: error: for each function it appears in.)
xml/apr_xml.c: In function ‘do_parse’:
xml/apr_xml.c:434: error: ‘apr_xml_parser’ has no member named ‘xp’
xml/apr_xml.c:438: error: ‘apr_xml_parser’ has no member named ‘xp’
xml/apr_xml.c:442: error: ‘apr_xml_parser’ has no member named ‘xp_err’
xml/apr_xml.c:442: error: ‘apr_xml_parser’ has no member named ‘xp’
xml/apr_xml.c: In function ‘apr_xml_parser_geterror’:
xml/apr_xml.c:500: error: ‘apr_xml_parser’ has no member named ‘xp_err’
xml/apr_xml.c:500: error: ‘apr_xml_parser’ has no member named ‘xp_err’
make[1]: *** [xml/apr_xml.lo] Error 1

1解決方案
https://sourceforge.net/projects/expat/files/
tar -xjvf ./soft/expat-2.2.6.tar.bz2 -C ./
./configure  
make
make install




錯誤2:安裝pcre
checking windows.h usability... no
checking windows.h presence... no
checking for windows.h... no
configure: error: Invalid C++ compiler or C++ compiler flags

解決方案 安裝 gcc-c++
參考 https://blog.csdn.net/qq1031893936/article/details/80396499
你可以去 http://rpmfind.net/ 這個網站挨個搜索下載下來。
鏈接:https://pan.baidu.com/s/1QDwYE1WC_vngJsqNSkZ5bQ 密碼:ny2d
rpm -Uvh *.rpm --nodeps --force




錯誤3:報錯:/usr/local/openssl/lib/libssl.a: could not read symbols: Bad value
刪除openssl舊包
重新解壓、重新編譯
./config -fPIC --prefix=/usr/local/openssl/ enable-shared
make
make install
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容