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. Tomcat8配置Https协议,Tomcat配置Https安全访问,Tomcat Https配置

    Tomcat8配置Https协议,Tomcat配置Https安全访问,Tomcat Https配置 ============================== ©Copyright 蕃薯耀 2017 ...

  2. Java 获取年 月 日 时 分 秒

    /** * 英文简写(默认)如:2010-12-01 */ public static String FORMAT_SHORT = "yyyy-MM-dd"; /** * 英文全称 ...

  3. Centos硬盘IO性能检测命令iostat[转]

    Centos硬盘IO性能检测命令iostat[转] 在Linux下频繁存取文件后,物理内存会很快被用光,当程序结束后,内存不会被正常释放,而是一直作为caching.这个问题,貌似有不少人在问,不过都 ...

  4. vs Code 运行一个本地WEB服务器

    VS Code作为前端开发工具,值得推荐,用上之后,爱不释手 当我们建立一个全静态的前端项目时,如果需要将整个项目运行起来也非常简单,两步即可: 1.安装npm install -g live-ser ...

  5. iOS UImage 与 RGB 裸数据的相互转换

    iOS UImage 与 RGB 裸数据的相互转换 Touch the data of image in iOS Get data from a image 较简单,根据已有的 image 的属性,创 ...

  6. Junit4X系列--hamcrest的使用

    OK,在前面的一系列博客里面,我整理过了Assert类下面常用的断言方法,比如assertEquals等等,但是org.junit.Assert类下还有一个方法也用来断言,而且更加强大.这就是我们这里 ...

  7. Linkin大话PC常用快捷键

    不管是不是程序员,常用的键盘的快捷键还是要会的,以下整理一些最常用的也比较重要的PC快捷键. 复制:CTRL+C 剪切:CTRL+X 粘贴:CTRL+V 全选:CTRL+A 撤销键:CTRL+Z 切换 ...

  8. MySQL模糊查询中通配符的转义

    sql中经常用like进行模糊查询,而模糊查询就要用到百分号“%”,下划线“_”这些通配符,其中“%”匹配任意多个字符,“_”匹配单个字符.如果我们想要模糊查询带有通配符的字符串,如“60%”,“us ...

  9. 浅谈python lambda

    lambda x: x * x,实际上就是 def f(x): retrun x * x 关键字lambda表示匿名函数,冒号前的x表示函数参数. 匿名函数只能有一个表达式,不用写return,返回值 ...

  10. javase学习小结二

    三角函数方法 Math.sin(radians):Math.sin(Math.PI/6)=0.5 Math.cos(radians):Math.cos(Math.PI/3)=0.5 Math.tan( ...