Ngix mobile End and PC side reverse proxy judgment

Source: Internet
Author: User
Tags nginx server user agent switcher

such as God Horse Search and Baidu (http://www.baidu.com), when using desktop browser and mobile browser access to the results are not the same. There are two possible ways to do this:

    • Reprint Ngix Reverse proxy judgment
    • The service side directly judges the UA output different interface, Java and PHP and other background languages provide support framework

Both have made a special page on the mobile side, so that the function of the demolition, the user experience of course greatly improved, but when there is a change in demand, often have to change two places.

With the advent of the mobile Internet era, many Web sites have launched a mobile client based on mobile phones, ipad and other page access, here is how to use the user UA to achieve user access under different terminal:

$http _user_agent is an nginx built-in parameter that allows you to specify what action to trigger when the user UA satisfies a certain type, and here we take the ipad as an example, configure separate access to the mobile and Web side, first edit the Nginx server {} program segment, Add the following information:

Location /{root/data/www/pc;if ($http _user_agent ~ iPad){ root /data/www/mobile; index index.html index.htm; }Reload Nginx, test time, if there is no ipad device, you can use the Firefox browser plug-in User Agent switcher to simulate a variety of devices, interested can check the usage of this plugin

Ngix mobile End and PC side reverse proxy judgment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.