How can I redirect HTTP requests made from an iPad?

前端 未结 17 2360
后悔当初
后悔当初 2020-12-12 09:53

Since on an iPad we cannot edit the hosts file (without jailbreaking), how can we arbitrarily redirect web traffic to another url?

This would be important for someth

17条回答
  •  旧巷少年郎
    2020-12-12 10:39

    If you already have an Apache server where you're doing dev, you can easily use it as a forward proxy. This is particularly useful for WordPress sites, which really love to use the full absolute URL.

    Ubuntu example below:

    The first step is to edit the /etc/hosts file in your dev server. Add the server's local IP, pointing to your site.

    127.0.0.1 dev.mysite.com

    This hosts file will be used by your Apache proxy when it tries to resolve requests from your iPhone / iPad. So let's setup the Apache part now...

    You may need to install some modules first.

    sudo apt-get install libapache2-mod-proxy-html
    sudo a2enmod proxy proxy_http proxy_html
    sudo apache2ctl graceful
    

    Then create a virtual host file, for example /etc/apache2/sites-available/my-proxy

    Listen *:8080
    
        ProxyRequests On
    
        
            Order Deny,Allow
            Deny from all
            Allow from 192.168.1.0/24 
        
    
    

    Enable the vhost, and restart Apache:

    sudo a2ensite my-proxy
    sudo apache2ctl graceful
    

    Then go to Settings > Wi-Fi > Your Network and configure a "Manual" proxy. Enter the IP of your Apache server, and the port. That's it!

    The block ensures that only people on my local network can use this proxy. Strictly limiting access is essential if you are using a forward proxy. The ip2cidr page will be helpful at this point. (As an extra measure, the :8080 port is blocked by my firewall.)

提交回复
热议问题