mac apached 代理搭建

1. OS x 10.11.3 Mac自带了Apache环境 

打开终端,执行 sudo apachectl start ,启动apache

启动未报错,ps -ef | grep -i httpd  命令可以查看到进程;

sudo vi /etc/hosts 如果没有,可添加 127.0.0.1 localhost 

浏览器地址栏输入 “http://localhost”,可以看到内容为“It works!”的页面。Apache的默认根目录为“/Library/WebServer/Documents/” 

2.设置虚拟主机和代理

2.1终端中执行 sudo vi /etc/apache2/httpd.conf,检查确保以下配置

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
未被用“#”注释掉;

2.2去掉httpd.conf 文件 “#Include /private/etc/apache2/extra/httpd-vhosts.conf”,前面的“” ;

2.3终端中执行 sudo vi /etc/apache2/extra/httpd-vhosts.conf,删除或注释掉模版中以下内容:

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/usr/docs/dummy-host.example.com"
    ServerName dummy-host.example.com
    ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
    CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common
VirtualHost>
 
<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/usr/docs/dummy-host2.example.com"
    ServerName dummy-host2.example.com
    ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log"
    CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
VirtualHost>
增加:

<VirtualHost *:80>

    DocumentRoot "/Users"
    ServerName mysites
    ErrorLog "/private/var/log/apache2/sites-error_log"
    CustomLog "/private/var/log/apache2/sites-access_log" common
    <Directory />
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order deny,allow
                Allow from all
      Directory>      

#正向代理设置

    ProxyRequests On  # 去掉或设置为off,可关闭代理

    ProxyVia On


   

        Order deny,allow

        Deny from all

        Allow from all

   

VirtualHost>
保存并退出。

3.sudo apachectl restart 重启apache服务。假设apache 服务所在服务器IP为192.168.1.132,

终端中telnet 192.168.1.132 80 显示Connected to localhost. 则为正常

4.在浏览器中配置代理参数IP为192.168.1.132,端口为80后,访问

https://www.baidu.com 可正常访问

你可能感兴趣的:(环境搭建)