Apache反向代理

作者: Yaso | 来源:发表于2018-11-07 19:19 被阅读1次

    一、Mac 自带apache服务器

    终端执行apachectl -h查看相应指令:

    Usage: /usr/sbin/httpd [-D name] [-d directory] [-f file]
                           [-C "directive"] [-c "directive"]
                           [-k start|restart|graceful|graceful-stop|stop]
                           [-v] [-V] [-h] [-l] [-L] [-t] [-T] [-S] [-X]
    Options:
      -D name            : define a name for use in <IfDefine name> directives
      -d directory       : specify an alternate initial ServerRoot
      -f file            : specify an alternate ServerConfigFile
      -C "directive"     : process directive before reading config files
      -c "directive"     : process directive after reading config files
      -e level           : show startup errors of level (see LogLevel)
      -E file            : log startup errors to file
      -v                 : show version number
      -V                 : show compile settings
      -h                 : list available command line options (this page)
      -l                 : list compiled in modules
      -L                 : list available configuration directives
      -t -D DUMP_VHOSTS  : show parsed vhost settings
      -t -D DUMP_RUN_CFG : show parsed run settings
      -S                 : a synonym for -t -D DUMP_VHOSTS -D DUMP_RUN_CFG
      -t -D DUMP_MODULES : show all loaded modules
      -M                 : a synonym for -t -D DUMP_MODULES
      -t -D DUMP_INCLUDES: show all included configuration files
      -t                 : run syntax check for config files
      -T                 : start without DocumentRoot(s) check
      -X                 : debug mode (only one worker, do not detach)
    

    二、apache反向代理:

    无法访问目标web时,使用目标web所在的网络内一台机器充当目标web的代理,客户端直接访问代理就像访问目标web一样.

    三、操作步骤

    1. 进入apache 配置文件所在目录:
    cd /etc/apache2
    
    1. 打开修改httpd.conf 文件
    subl httpd.conf
    
    //开启
    LoadModule proxy_module libexec/apache2/mod_proxy.so
    LoadModule proxy_connect_module libexec/apache2/mod_proxy_connect.so
    LoadModule proxy_ftp_module libexec/apache2/mod_proxy_ftp.so
    LoadModule proxy_http_module libexec/apache2/mod_proxy_http.so
    LoadModule proxy_balancer_module libexec/apache2/mod_proxy_balancer.so
    
    //新增
    
    <VirtualHost *:80>
          ServerName test.ele.me   //目标web
          ProxyRequests off  
          Header set Access-Control-Allow-Origin *
          <Proxy *>
              Order deny,allow
              Allow from all
          </Proxy>
          <Location />
              ProxyPass http://127.0.0.1:4442/      
              ProxyPassReverse http://127.0.0.1:4442/   //需反向web
          </Location>
    </VirtualHost>
    
    

    3.重启生效

    sudo apachectl -k restart
    

    相关文章

      网友评论

        本文标题:Apache反向代理

        本文链接:https://www.haomeiwen.com/subject/beyvxqtx.html