Apache反向代理设置方法

时间:2022-11-23 14:43:44

打开 apache 安装目录的 conf 文件夹(linux 在 /etc/httpd/conf 或者 /usr/local/apache/conf)

打开 httpd.conf

把 

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

前面的注释去掉

在 httpd.conf 最后添上

NameVirtualHost *:80

<VirtualHost *:80>
ServerName www.truemv.com
ServerAlias www.truemv.com
ProxyRequests Off
<Proxy http://www.truemv.com>
        Options MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Proxy>
ProxyPass / http://61.191.191.4:9002/
ProxyPassReverse / http://61.191.191.4:9002/
</VirtualHost>

<VirtualHost *:80>
ServerName img.truemv.com
ServerAlias img.truemv.com
ProxyRequests Off
<Proxy http://img.truemv.com>
        Options MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Proxy>
ProxyPass / http://61.191.191.4:9003/
ProxyPassReverse / http://61.191.191.4:9003/
</VirtualHost>

其中
NameVirtualHost *:80
这句话是告诉apache用域名来区分访问来源,apache支持用域名和ip两种,用ip的话,你的机子上的VirtualHost需要绑定多个ip

附录:

<VirtualHost *:9002>
ServerName localhost
ServerAlias localhost
DocumentRoot "x:/xxxx/upload/"
<Directory "x:/xxxx/upload/">
    Options MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
RewriteEngine on  
RewriteRule ^/artist-(\d+).html$ /artist.php?id=$1  
RewriteRule ^/theme-(\d+).html$ /theme.php?themeid=$1  
RewriteRule ^/artist-list-(.+).html$ /artist_list.php?tp=$1  
RewriteRule ^/theme-list.html$ /theme_list.php
</VirtualHost>

<VirtualHost *:9003>
ServerName localhost
ServerAlias localhost
DocumentRoot "x:/xxxx/mv_img/"
<Directory "x:/xxxx/mv_img/">
    Options MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
</VirtualHost>


AddType video/x-flv .flv

<VirtualHost *:9004>
ServerName localhost
ServerAlias localhost
DocumentRoot "x:/xxxx/vod/"
<Directory "x:/xxxx/vod/">
    Options MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
</VirtualHost>

<VirtualHost *:9005>
ServerName localhost
ServerAlias localhost
DocumentRoot "x:/xxxx/vod2/"
<Directory "x:/xxxx/vod2/">
    Options MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
</VirtualHost>

<VirtualHost *:9006>
ServerName localhost
ServerAlias localhost
DocumentRoot "x/truemv_wap/"
<Directory "x:/truemv_wap/">
    Options MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
    DirectoryIndex index.php
</Directory>
</VirtualHost>

<VirtualHost *:9007>
ServerName localhost
ServerAlias localhost
DocumentRoot "x:/xxx/xxx/"
<Directory "x:/xxx/xxx/">
    Options MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
    DirectoryIndex index.php
</Directory>
</VirtualHost>

<VirtualHost *:9008>
ServerName localhost
ServerAlias localhost
DocumentRoot "x:/xxxx/xxx/"
<Directory "x:/xxxx/xxx/">
    Options MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
    DirectoryIndex index.php
</Directory>
</VirtualHost>