Apache的反向代理主要利用转发模块,proxy和proxy_http

先配置 Apache 支持proxy 和 proxy_http

在Ubuntu系统下,Apache的配置文件在目录/etc/apache2下,里面会看到我们需要用到的两个目录

mods-available Apache所有的模块

mods-enabled  Apache所支持的模块

接下来需要进入mods-available 找到proxy.load和proxy_http.load 这两个模块,将这两个模块配置到mods-enabled

输入命令:

ln -s /etc/apache2/mods-available/proxy.load  /etc/apache2/mods-enabled/proxy.load

ln -s /etc/apache2/mods-available/proxy_http.load  /etc/apache2/mods-enabled/proxy_http.load

模块开通好了以后,接下来要配置一个虚拟主机,然后将虚拟主机的请求转发到指定的服务器上。

配置虚拟主机

同样也是在/etc/apache2下面有个关于虚拟主机的配置目录:

sites-available 所有可用的虚拟主机

sites-enabled  已经配置支持的主机

首先进入 sites-available 将000-default.conf拷贝并重命名为proxy.conf

编辑proxy.conf

<VirtualHost *:80>

# The ServerName directive sets the request scheme, hostname and port that

# the server uses to identify itself. This is used when creating

# redirection URLs. In the context of virtual hosts, the ServerName

# specifies what hostname must appear in the request's Host: header to

# match this virtual host. For the default virtual host (this file) this

# value is not decisive as it is used as a last resort host regardless.

# However, you must set it for any further virtual host explicitly.

ServerName example.cn  自定义的主机域名

ServerAdmin webmaster@localhost

DocumentRoot /var/www/html 指向的目录

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,

# error, crit, alert, emerg.

# It is also possible to configure the loglevel for particular

# modules, e.g.

#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log

CustomLog ${APACHE_LOG_DIR}/access.log combined

ProxyPass / http://localhost:81/  转发的主机与端口号

ProxyPassReverse / http://localhost:81/ 如果有页面的重定向,不加此项会报错,此项正是反向代理

# For most configuration files from conf-available/, which are

# enabled or disabled at a global level, it is possible to

# include a line for only one particular virtual host. For example the

# following line enables the CGI configuration for this host only

# after it has been globally disabled with "a2disconf".

#Include conf-available/serve-cgi-bin.conf

</VirtualHost>

重启Apache,即可。

Ubuntu下利用Apache转发模块实现反向代理的更多相关文章

  1. ubuntu下ssh设置firefox用的反向代理

    mark一下: ssh -D 127.0.0.1:8080 -l root MyIp

  2. Ubuntu下配置Apache的Worker模式

    其实Apache本身的并发能力是足够强大的,但是Ubuntu默认安装的是Prefork模式下的Apache.所以导致很多人后面盲目的去 安装lighttpd或者nginx一类替代软件.但是这类软件有一 ...

  3. ubuntu下在apache部署python站点

    ubuntu下在apache部署python站点 我的是ubuntu14 32为的虚拟机,默认安装的python为3.4 环境:apache + mysql + django + python3 软件 ...

  4. Ubuntu下关闭apache和mysql的开机启动

    Ubuntu下关闭apache和mysql的开机启动 sudo apt-get install sysv-rc-conf sudo sysv-rc-conf sudo vi /etc/init/mys ...

  5. ubuntu下配置Apache

    ubuntu下配置Apache Apache的默认文档根目录是在Ubuntu上的/var/www目录 配置文件是/ etc/apache2/apache2.conf配置存储在的子目录在/etc/apa ...

  6. upstream模块实现反向代理的功能

    nginx平台初探(100%) — Nginx开发从入门到精通 http://tengine.taobao.org/book/chapter_02.html#id6 nginx的模块化体系结构¶ ng ...

  7. ubuntu 下搭建apache+python的运行环境

    ubuntu下怎么搭建apache+python运行环境,可以参考http://www.01happy.com/ubuntu-apache-mod-python/ ,这里只是简单的记录下步骤,本文主要 ...

  8. ubuntu下的apache+php+mysql的安装

    平时我都时在windows下搭配apache+php+mysql环境的,只不过后来听别人说在linux下搭配apache+php+mysql更受欢迎,而且一般公司也是用这样的搭配,所以今天在试着在ub ...

  9. ubuntu下配置Apache+mod_wsgi+Django项目(个人测试)

    经过了一个星期的摸索,查找资料以及实验,我搭建的环境基本能用(还有就是Django后台的静态文件加载的问题) 这里面只是介绍一下我的过程,因为对应Apache还不是很熟练,特别是配置文件.只能供大家参 ...

随机推荐

  1. 使用wrk进行性能测试

    1 wrk介绍 wrk是一款现代化的HTTP性能测试工具,即使运行在单核CPU上也能产生显著的压力.它融合了一种多线程设计,并使用了一些可扩展事件通知机制,例如epoll and kqueue. 一个 ...

  2. ios 继承关系图

  3. Python-Blog2-编写Web app 骨架

    撸代码之前让我们先来看几个概念: 什么是协程(Coroutine)? 假设现在有两个子程序,子程序A和子程序B: def A(): print('1') print('2') print('3') d ...

  4. WebSphere--基本特性

    WebSphere应用服务器使您能够为Servlet 的开发实现 "一次写成,各处使用"的目的.该产品包括一个基于 Java 的 Servlet 引擎,独立于 Web 服务器和它所 ...

  5. 《struts2》:指定多个配置文件和默认Action

    转载:http://m.blog.csdn.net/article/details?id=51212968

  6. JMeter之断言 - 响应文本

    1.  响应数据: 2.  添加响应断言: 3.设置响应断言,本例中 设置 响应文本 中 包括 success 字符串的 为真,即通过. 4.如果设置 响应文本 中 包括 error 字符串的 为真, ...

  7. __init__class的简单使用/理解

    # -*- coding: utf-8 -*- class Student(object): def __init__(self, name, score): #通过定义一个特殊的__init__方法 ...

  8. CSS——类和ID选择器的区别

    1.相同点,可以应用在任何元素. 2.不同点,ID选择器只能在元素里只能分别引用,不能同时引用. 如: <style type="text/css">.stress{( ...

  9. Akamai CDN

    Akamai CDN中的几个重要组件 mapping system 调度系统(映射client到edge cluster,进而到edge server) edge server platform 边缘 ...

  10. Sql Server的艺术(三) SQL聚合函数的应用

    SQL提供的聚合函数有求和,最大值,最小值,平均值,计数函数等. 聚合函数及其功能: 函数名称 函数功能 SUM() 返回选取结果集中所有值的总和 MAX() 返回选取结果集中所有值的最大值 MIN( ...