设置Apache作为前端代理服务器

参考资料:
https://www.digitalocean.com/community/tutorials/how-to-use-apache-http-server-as-reverse-proxy-using-mod_proxy-extension
http://aiyiweb.com/apache/2735
http://blog.csdn.net/flynetcn/article/details/3733592
https://wenku.baidu.com/view/6b532a6db84ae45c3b358c42.html

关键点:
模块使能命令: a2enmod [模块名称]
a2enmod proxy
a2enmod proxy_http
a2enmod proxy_ajp
a2enmod rewrite
a2enmod deflate
a2enmod headers
a2enmod proxy_balancer
a2enmod proxy_connect
a2enmod proxy_html
a2enmod xml2enc

配置文件设置:
/etc/apache2/sites-enabled/000-default.conf

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 www.example.com

    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

    # 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
       ProxyPreserveHost On   #这里开启功能

    # Servers to proxy the connection, or;
    # List of application servers:
    # Usage:
    # ProxyPass / http://[IP Addr.]:[port]/
    # ProxyPassReverse / http://[IP Addr.]:[port]/
    # Example: 
        ProxyPass /proxy http://www.baidu.com/   #这里设置正向代理,格式:命令 过滤条件 指向网站
        ProxyPassReverse / http://www.errmx.com/  #这里设置反向代理,格式:命令 过滤条件 指向网站
        #例如,指定访问http://127.0.0.1/proxy时转向http://www.google.com/earth
        #ProxPass /proxy http://www.google.com/earth
        #ProxyPassReverse /proxy http://www.google.com/earth

        ServerName localhost


# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

你可能感兴趣的:(c语言)