源代码构建Apache反向代理(包括SSL配置)

简介:

由rpm构建的apache是适合大多数场合的应用,它包含了大多数的模块,而我们只是用它去构建反向代理,过多大模块反而不好,影响了性能,所以我们选择了针对性的源代码编译,让apache去适应我们的平台。

下载源代码:

wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.25.tar.gz

解压

tar zxvf httpd-2.2.25.tar.gz

cd httpd-2.2.25

编译安装的前提条件

yum install -y gcc gcc-c++ apr apr-devel apr-util openssl openssl-devel

根据gcc版本,和cpu架构,进行优化编译

clip_image002

使用gcc -v查看gcc的版本

clip_image004

cat /proc/cpuinfo 查看cpu型号

clip_image005

uname –r 查看 操作系统的版本

clip_image006

编译安装

CFLAGS="-march=core2 -mtune=generic -O2 -pipe" CXXFLAGS="{CFLAGS}" ./configure --enable-layout=RedHat --enable-modules=so --enable-ssl --enable-rewrite --enable-proxy

make

make install

清除调试符号,节省内存空间

strip /usr/sbin/httpd

使用httpd –M检查添加的模块

httpd -m |grep rewrite

httpd -m |grep ssl

httpd -m |grep proxy

clip_image007

使用httpd -k start 启动apache

使用 httpd -k stop 关闭

使用 httpd -k restart 重启

echo “/usr/sbin/httpd –k start” >>/etc/rc.local 设为随机启动

配置ssl

红色字体为新添加的配置

#redirect non-ssl request to ssl requres

Redirect / https://web.contoso.com

SSLSessionCache "shmcb:logs/ssl_scache(512000)"

SSLSessionCacheTimeout 300

ProxyRequests off

listen 443 https

NameVirtualHost *:443

<VirtualHost *:443>

# Site info

ServerName webprox1.contoso.com

ServerAdmin administrator@contoso.com

SSLEngine on

SSLProxyEngine on

SSLCertificateFile /etc/httpd/conf/ssl/web.crt

SSLCertificateKeyFile /etc/httpd/conf/ssl/web.key

SSLCACertificatePath /etc/httpd/conf/ssl

SSLCACertificateFile /etc/httpd/conf/ssl/ca.pem

# Rewrite engine on

RewriteEngine On

RewriteOptions Inherit

# Log filenames

ErrorLog /etc/httpd/logs/error-inotes-redirect

CustomLog /etc/httpd/logs/access-inotes-redirect common

LogLevel warn

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

# Rule 0 : If Cookie is set and user logs out, remove the cookie

RewriteCond %{HTTP_COOKIE} ^.*iNotesServer=.*

RewriteCond %{QUERY_STRING} ^Logout

RewriteRule ^/.* - [CO=iNotesServer:domino1:.contoso.com:1]

# Rule 1 : Read domino server name from first access to the mail directory,

# save it to the cookie and redirect to the mail server

RewriteCond %{REQUEST_URI} ^/(.*)/mail

RewriteRule /(.*)/mail/(.*) http://$1.contoso.com/mail/$2 [P,CO=iNotesServer:$1:.contoso.com]

# Rule 2 : If cookie is set, use it to rewrite rules for iNotes generated URLs

# and non mail DBs for the server definde in the cookie iNotesServer

RewriteCond %{REQUEST_URI} ^/favicon.ico [OR]

RewriteCond %{REQUEST_URI} ^/domjs [OR]

RewriteCond %{REQUEST_URI} ^/domjava [OR]

RewriteCond %{REQUEST_URI} ^/domcfg.nsf [OR]

RewriteCond %{REQUEST_URI} ^/iNotes [OR]

RewriteCond %{REQUEST_URI} ^/icons [OR]

RewriteCond %{REQUEST_URI} ^/iwaredir.nsf [OR]

RewriteCond %{REQUEST_URI} ^/names.nsf [OR]

RewriteCond %{REQUEST_URI} ^/mail [OR]

RewriteCond %{REQUEST_URI} ^/archive [OR]

RewriteCond %{REQUEST_URI} ^/download [OR]

RewriteCond %{REQUEST_URI} ^/dwa(.*)

RewriteCond %{HTTP_COOKIE} ^.*iNotesServer=([^;]+)

RewriteRule /(.*) http://%1.contoso.com/$1 [P,L]

# Rule 3 : if no cookie set -> on first access on the iNotes iwaredir.nsf

RewriteCond %{REQUEST_URI} ^/favicon.ico [OR]

RewriteCond %{REQUEST_URI} ^/domcfg.nsf [OR]

RewriteCond %{REQUEST_URI} ^/iwaredir.nsf [OR]

RewriteCond %{REQUEST_URI} ^/names.nsf

RewriteRule /(.*) http://domino1.contoso.com/$1 [P,L]

# Rule 4 : everything else should be redirected to the original link

RewriteCond %{REQUEST_URI} ^/

RewriteRule / http://domino1.contoso.com/ [P]

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

ProxyPassReverse /domino1/mail/ http://domino1.contoso.com/mail/

ProxyPassReverse / http://domino1.contoso.com/

</VirtualHost>

clip_image009

性能优化

取消http.conf中

Include /etc/httpd/conf/extra/httpd-mpm.conf 的注释,即删除前面的#号

修改 prefork段的值

<IfModule mpm_prefork_module>

ServerLimit 1000

StartServers 15

MinSpareServers 15

MaxSpareServers 20

MaxClients 1000

MaxRequestsPerChild 3000

</IfModule>




本文转自 高文龙 51CTO博客,原文链接:http://blog.51cto.com/gaowenlong/1281165,如需转载请自行联系原作者

相关文章
|
1月前
|
消息中间件 存储 关系型数据库
使用Apache Hudi构建下一代Lakehouse
使用Apache Hudi构建下一代Lakehouse
38 0
|
1月前
|
SQL Apache HIVE
一文彻底掌握Apache Hudi的主键和分区配置
一文彻底掌握Apache Hudi的主键和分区配置
61 0
|
1天前
|
安全 应用服务中间件 网络安全
SSL原理、生成SSL密钥对、Nginx配置SSL
现在,你的Nginx虚拟主机应该已经配置了SSL,可以通过HTTPS安全访问。确保在生产环境中使用有效的SSL证书来保护通信的安全性。
6 0
|
6天前
|
消息中间件 存储 Java
深度探索:使用Apache Kafka构建高效Java消息队列处理系统
【4月更文挑战第17天】本文介绍了在Java环境下使用Apache Kafka进行消息队列处理的方法。Kafka是一个分布式流处理平台,采用发布/订阅模型,支持高效的消息生产和消费。文章详细讲解了Kafka的核心概念,包括主题、生产者和消费者,以及消息的存储和消费流程。此外,还展示了Java代码示例,说明如何创建生产者和消费者。最后,讨论了在高并发场景下的优化策略,如分区、消息压缩和批处理。通过理解和应用这些策略,可以构建高性能的消息系统。
|
14天前
|
域名解析 网络协议 应用服务中间件
阿里云SSL证书配置(HTTPS证书配置)
该内容是一个关于如何在阿里云上准备和购买SSL证书,以及如何为网站启用HTTPS的步骤指南。首先,需要注册并实名认证阿里云账号,然后在SSL证书控制台选择证书类型、品牌和时长进行购买。申请证书时填写域名信息,并进行DNS验证,这包括在阿里云域名管理板块添加解析记录。完成验证后提交审核,等待证书审核通过并下载Nginx格式的证书文件。最后,将证书配置到网站服务器以启用HTTPS。整个过程涉及账户注册、实名认证、证书购买、DNS设置和证书下载及安装。
77 0
|
26天前
|
前端开发 应用服务中间件 网络安全
http转为https,ssl证书安装及nginx配置
http转为https,ssl证书安装及nginx配置
41 1
|
1月前
|
安全 Linux 网络安全
Qt SSL/TLS 安全通信类:构建安全网络应用的关键组件
Qt SSL/TLS 安全通信类:构建安全网络应用的关键组件
64 0
|
1月前
|
XML Java Apache
Apache Flink自定义 logback xml配置
Apache Flink自定义 logback xml配置
150 0
|
1月前
|
SQL 分布式计算 NoSQL
使用Apache Hudi和Debezium构建健壮的CDC管道
使用Apache Hudi和Debezium构建健壮的CDC管道
16 0
|
1月前
|
监控 API Apache
实战!配置DataDog监控Apache Hudi应用指标
实战!配置DataDog监控Apache Hudi应用指标
21 0

推荐镜像

更多