How can I redirect HTTP requests made from an iPad

2019-01-20 22:01发布

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 something such as developing a website that uses a Virtual Host configuration where you want to redirect to a development machine.

(This is related to this question: Can I edit an iPad's host file?)

16条回答
女痞
2楼-- · 2019-01-20 22:44

I made it by using squidman on Mac. It's easy to set up and use.
I set it up in 5 minutes by following this article.

Update

Another thing is if you want to connect to the websites running on proxy server, in my case it's my Mac, you need to comment this line out in squidman->Preferences->Template

# protect web apps running on the proxy host from external users
# http_access deny to_localhost
查看更多
我命由我不由天
3楼-- · 2019-01-20 22:44

If you have a live website you can use for this:

You can add an A record to your DNS configuration: something.yourdomain.com which points to your local IP address, then add an entry for something.yourdomain.com to your virtual hosts file. Restart Apache, get your iOS device on the same network and you're good to go.

查看更多
淡お忘
4楼-- · 2019-01-20 22:45

I need to test web apps I am developing on an iPad. I use Apache on my dev machine to run the web apps, so the easiest solution I found was to use Apache mod_proxy.

My dev machine is visible on my home network as sapphire.local.

The web app I am testing is at hosted on the dev machine at demo.cms.dev (I am using POW).

To setup the proxy, I added the following section to httpd.conf.

<VirtualHost *:80>
  ServerName sapphire.local
  ProxyPass / http://demo.cms.dev/
  ProxyPassReverse / http://demo.cms.dev/
  ProxyPassReverseCookieDomain .cms.dev .sapphire.local
  ProxyPreserveHost Off
</VirtualHost>

This routes incoming requests on sapphire.local to demo.cms.dev. The method only works for one app at a time. I think you could use different ports to setup additional apps. Maybe someone has a better solution?

查看更多
可以哭但决不认输i
5楼-- · 2019-01-20 22:45

You could setup an internal DNS server on your network (if one does not exist already) and setup an A record. Then ensure your DHCP is set to return said DNS server

查看更多
我命由我不由天
6楼-- · 2019-01-20 22:49

I found you just have to modify the Wifi settings in your iPad to use the IP address of your development machine as an HTTP proxy (as explained in the aforementioned article):

enter image description here

That way, it's enough to be able to access your web application on your iPad by entering the url of the virtual host (e.g. local.mywebapp.com). It's easy and quick, but unlike Will Koehler's solution, you will however not be able to access Internet from the iPad. But most of the time it's not really a problem, since you just want to test your own application.

查看更多
等我变得足够好
7楼-- · 2019-01-20 22:49

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
<VirtualHost *:8080>
    ProxyRequests On

    <Proxy *>
        Order Deny,Allow
        Deny from all
        Allow from 192.168.1.0/24 
    </Proxy>
</VirtualHost>

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 <Proxy *> 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.)

查看更多
登录 后发表回答