【茶余饭后】安装Apache配置正向代理和反向代理
发布日期:2021-06-24 15:29:02
浏览次数:3
分类:技术文章
本文共 4229 字,大约阅读时间需要 14 分钟。
文章目录
Apache安装(离线)
1、准备必要软件包
- apr-1.4.5.tar.gz 注:APR(Apache portable Run-time libraries,Apache可移植运行库)的目的如其名称一样,主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库。相当于apache的虚拟环境
- apr-util-1.3.12.tar.gz apr-util安装依赖于apr,因此需要首先安装apr。常用的一些存储段和存储段组,加密组件等等
- httpd-2.2.31.tar.gz apache的核心软件,也是http的主程序
- pcre-8.10.zip
2、解压编译
默认解压路径为“/opt/”
1. 依赖包安装apr-1.4.5.tar.gz1. tar -xzvf apr-1.4.5.tar.gz 2. cd apr-1.4.5 3. yum -y install gcc-c++ 4. ./configure --prefix=/usr/local/apr 5. make && make install
2. 依赖包安装apr-util-1.3.12.tar.gz
1. tar -xzvf apr-util-1.3.12.tar.gz 2. cd apr-util-1.3.12 3. ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config 4. make && make install
3. 依赖包安装pcre.8.10.zip
1. tar -xzvf pcre-8.10.zip 或者 unzip pcre-8.10.zip 2. cd pcre-8.10 2. ./configure --prefix=/usr/local/pcre 3. make && make install
4. Apache安装
1. tar zxvf httpd-2.2.31.tar.gz 2. yum install zlib-devel -y 3. cd httpd-2.2.31 4. ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --enable-modules=so --enable-mods-shared=all --enable-proxy --enable-proxy-connect --enable-proxy-ftp --enable-proxy-http --enable-proxy-ajp --enable-proxy-balancer --enable-rewrite --enable-ssl --with-ssl=/usr/local/httpd/ssl --with-expat=builtin ap_cv_void_ptr_lt_long=no --with-z=/usr/lib/ 5. make && make install
以上执行会报错,configure: error: …No recognized SSL/TLS toolkit detected,这是需要先执行第五步中的“yum install openssl*”,若不需要代理https的,可以把以上第四步中的*–enable-ssl --with-ssl=/usr/local/httpd/ssl*给去掉
5. 使用https代理需要安装ssl1. yum install openssl*2. openssl genrsa -des3 1024 > /usr/local/apache2/conf/server.key3. openssl genrsa -des3 1024 > /usr/local/apache2/conf/server.key > /usr/local/apache2/conf/server2.key 4. mv /usr/local/apache2/conf/server2.key /usr/local/apache2/conf/server.key5. openssl req -new -key /usr/local/apache2/conf/server.key -out /usr/local/apache2/conf/server.csr6. openssl x509 -in /usr/local/apache2/conf/server.csr -out /usr/local/apache2/conf/server.crt -req -signkey /usr/local/apache2/conf/server.key -days 3650
该生成的证书路径需要和apache创建后的host_ssl.conf中的SSL证书路径一致,查看证书信息“openssl x509 -noout -text -in server.crt”
3、验证Apache
1. 启动Apache
###由于在安装apache的时候指定的安装前缀是/usr/local/apache21. cd /usr/local/apache2/bin2. ./apachectl start###报错:httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
报错httpd: Could not reliably determine the server’s fully qualified domain name, using localhost.localdomain for ServerName,需要在原始的httpd.conf文件中配置ServerName,如下:
3. cd /usr/local/apache2/conf4. vim httpd.conf###使用:set number 打开行号找到157行,或者使用?ServerName找到位置,在原来的下面新增一行6. ServerName localhost:80然后重新启动apache,./apachectl restart 以上其实并没有结束,可以查看端口启用情况
netstat -na | grep 80
发现并没有启动成功
下面需要进一步配置apache 2. 配置Apache 首先修改主配置httpd.conf1. cd /usr/local/apache2/conf/2. vim httpd.conf####保证一下模块处于开启的状态,前面有#号的去掉#LoadModule proxy_module modules/mod_proxy.so #LoadModule proxy_connect_module modules/mod_proxy_connect.so#LoadModule proxy_http_module modules/mod_proxy_http.so#LoadModule proxy_ajp_module modules/mod_proxy_ajp.so#LoadModule proxy_balancer_module modules/mod_proxy_balancer.so#Include conf/extra/httpd-vhosts.conf#####如果使用到了https的反向代理,需要打开下面这个配置#Include conf/extra/httpd-vhosts.conf
其次修改虚拟主机的httpd配置,即httpd-vhosts.conf
以下同时使用80端口做了正向代理和反向代理,仅供参考DocumentRoot "/usr/local/apache2/shared" ServerName xxx.xxx.xxx.xxx:80 ErrorLog "/usr/local/apache2/logs/error.log" CustomLog "/usr/local/apache2/logs/access.log" common SetEnvIfNoCase Referer ^http://xxx.xxx.xxx.xxx:80 local_ref SetEnvIf Referer ^$ local_ref ###作为https的反向代理必须加上以下的配置 SSLProxyEngine on ###以下作为https的反向代理配置 ProxyPass /wechat https://weixin.qq.com ProxyPassReverse /wechat https://weixin.qq.com Require all denied Options FollowSymLinks AllowOverride None Order deny,allow Allow from all ###以下是作为正向代理的配置 ProxyRequests On ProxyVia OnOrder deny,allow Deny from all Allow from all SetOutputFilter DEFLATE SetEnvIfNoCase Request_URI "\.(?:rar|json|g?zip)$" no-gzip
重启apache,然后再查看端口启用情况即可
转载地址:https://blog.csdn.net/weixin_33602978/article/details/106038444 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
逛到本站,mark一下
[***.202.152.39]2024年04月16日 21时48分53秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
那些年,陪你度过最困难时光的女孩还在么?
2021-07-01
关于我
2021-07-01
你可能不知道的 AS 小技巧之「Extract Resource」
2021-07-01
Android Studio 2.2 来啦
2021-07-01
「微信小程序」有哪些冲击与机会?
2021-07-01
移动开发 or web 前端?
2021-07-01
想的太多,做的太少
2021-07-01
一劳永逸学 SQL
2021-07-01
职场的核心竞争力,其实只有一个
2021-07-01
中奖名单公布
2021-07-01
月薪三万,依然买不起房
2021-07-01
谈谈如何才能高薪
2021-07-01
匿名不是法外之地
2021-07-01
计算机底层第一课,早学早受益
2021-07-01
我创业这半年
2021-07-01
要不要转行?
2021-07-01
月薪 1 万和 10 万的人,到底差在哪儿?
2021-07-01
年薪百万是种怎样的体验
2021-07-01
大家赚点小钱吧
2021-07-01
推荐一些优质原创公众号
2021-07-01