一、apache(不推荐):

  1. 代理80端口:
    a. 配置:
    apache、nginx实现反向代理
    b. 效果:
    apache、nginx实现反向代理_第1张图片
    c. 配置文件参考:
    ServerRoot "/etc/httpd"
    Listen 80
    ProxyPass / http://admin.dollarphp.com/
    ProxyPa***everse / http://admin.dollarphp.com/
    Include conf.modules.d/*.conf
    User apache
    Group apache
    ServerAdmin root@localhost
    
    AllowOverride none
    Require all denied
    
    DocumentRoot "/var/www/html"
    
    AllowOverride None
    Require all granted
    
    
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
    
    
    DirectoryIndex index.html
    
    
    Require all denied
    
    ErrorLog "logs/error_log"
    LogLevel warn
    
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common
    
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    
    CustomLog "logs/access_log" combined
    
    
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
    
    
    AllowOverride None
    Options None
    Require all granted
    
    
    TypesConfig /etc/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
    
    AddDefaultCharset UTF-8
    
    MIMEMagicFile conf/magic
    
    EnableSendfile on
    IncludeOptional conf.d/*.conf
  2. 代理443端口:
    a. 安装mod_ssl:
    yum  -y  install  mod_ssl

    b. 配置:
    apache、nginx实现反向代理
    c. 效果:
    apache、nginx实现反向代理_第2张图片
    d. 配置文件参考:

    ServerRoot "/etc/httpd"
    Listen 80
    SSLProxyEngine on
    ProxyPass / https://www.baidu.com/
    ProxyPa***everse / https://www.baidu.com/
    Include conf.modules.d/*.conf
    User apache
    Group apache
    ServerAdmin root@localhost
    
    AllowOverride none
    Require all denied
    
    DocumentRoot "/var/www/html"
    
    AllowOverride None
    Require all granted
    
    
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
    
    
    DirectoryIndex index.html
    
    
    Require all denied
    
    ErrorLog "logs/error_log"
    LogLevel warn
    
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common
    
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    
    CustomLog "logs/access_log" combined
    
    
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
    
    
    AllowOverride None
    Options None
    Require all granted
    
    
    TypesConfig /etc/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
    
    AddDefaultCharset UTF-8
    
    MIMEMagicFile conf/magic
    
    EnableSendfile on
    IncludeOptional conf.d/*.conf

    二、nginx(同时适用于80端口和443端口):

  3. 配置:
    apache、nginx实现反向代理
  4. 配置文件参考:
    user nginx;
    worker_processes auto;
    error_log /var/log/nginx/error.log;
    pid /run/nginx.pid;
    include /usr/share/nginx/modules/*.conf;
    events {
    worker_connections 1024;
    }
    http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    include /etc/nginx/conf.d/*.conf;
    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;
        include /etc/nginx/default.d/*.conf;
        location / {
            proxy_pass https://www.baidu.com;
        }
        error_page 404 /404.html;
            location = /40x.html {
        }
        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
    }