In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail the method of nginx configuring PC stations to separate mobile stations to achieve redirection. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Use nginx to configure PC station mobile station separation, my PC station and mobile station are written by nuxt framework, because nuxt convenient SEO,nuxt is based on the improvement of vue, do not know consciously search nuxt
1. Install nginx based on APT source
Sudo apt-get install nginx
2. Create a new configuration file test.com under the specified directory: the file name is arbitrary.
/ / the directory is in / etc/nginx/sites-available/
3. Edit the configuration file and content:
There may be problems when editing files, insufficient permissions, and so on:
1. You can use sudo vi or install vim before using sudo vim to edit the file
3. Enter the password directly using sudo su and switch to root user
2, you can also modify the permissions of the entire nginx folder directly by chmod 777 / etc/nginx.
Server {listen 80; server_name kason995.com; set $mobile_rewrite do_not_perform; if ($http_user_agent ~ * "(android | bb\ d+ | meego). + mobile | avantgo | bada\ / | blackberry | blazer | compal | elaine | hiptop | iemobile | ip (hone | od | ad) | iris | kindle | lge | maemo | midp | mmp | mobile.+firefox | netfront | opera m (ob | in) I | palm (os)? | phone | p (ixi | ixi)\ / | phone | ixi | re (4 | 6) 0 | plucker |\. (|) | | } if ($http_user_agent ~ * "^ (1207 | 6310 | 6590 | 3gso | 4thp | 50 [1-6] I | 770s | 802s | a wa | ac (er | oo | s\ -) | ai (ko | rn) | al (av | ca | co) | amoi | an (ex | ny | yw) | aptu | ar (ch | go) | as (te | us) | attw | au (di |\-m | r | s) | avan | be (ck | ll | nq) | nq (nq) | nq (nq) | bi (nq) | bi (bi |) | Jun (e | v) w | lb | lb\-(n | u) | C55\ /) | lb | lb\-/ lb | lb | lb\-rd | lb | | be\-Cun | | be | Lao | | Ic | K0) | esl8 | ez ([4-7] 0 | os | wa | ze) | fetc | fly (\-| _) | G1 u | G560 | gene | gf\-5 | g\-mo | go (\ .w | od) | gr (ad | un) | haie | hcit | hd\-(m | t) | hei\-| hi (pt | ta) | hp (I | ip) | hs\-c | ht (\-| | _ | a | g | p | s | t) | tp) | hu (aw | tc) | I\-(20 | go | ma) | i230 | iac (\-|\ /) | ibro idea | idea | ig01 | idea | ig01 | ig01 (t) | ikom (v) | | ikom | ikom (/ /) | im1k (I | ip) | | idea (/) | | ikom (/ /) | | idea (/ /) | 54 / u | | 54 |\ k | | libw | lynx | M1\-w | m3ga | M50\ / | ma (te | ui | xo) | mc (01 | 21 | ca) | m\-cr | me (rc) | mi (o8 | oa | ts) | mmef | mo (01 | 02 | bi | de | do | t (\-| o | v) | zz) | mt (50 | p1 | v) | mwbp | mywa | N10 [0-2] | N20 [2-3] | N30 (0 | 2) | N50 (0 | 2 | 5) | N7 (0 (0 | 1) | 10) | ne (c | m)\-| on tf wf | wg | wt) | nok (6) | nzph o2im | op (ti) | ti ti (ti) | wv | ti | ti (ti) | ti | wv (a d | t) | wv | 13 (\-c | 1 | 8) | owg1 | oran | 2 | oran | | | prox | psio | pt\-g | qa\-a | qc (07 | 12 | 21 | 32 |\-[2-7] | I\ -) | qtek | R380 | R600 | raks | rim9 | ro (ve | zo) | S55\ / | sa (ge | ma | mm | ms | ny | va) | sc (01 | h\-| oo | p\ -) | sdk\ / | se (c (\-| 0 | 1) | 47 | mc | nd | ri) | sgh\-| shar sie (\-m) | sk\-0 | sl (45 | id) | sm (al | ar | b3 | it | T2) | so (so) | ft (so) | so (so) | (01 | h\-v\-| v) | ft (ny) | 18 (50) | 18 | 50) | T6 (10) | 10) | 18) (ny) | sp\-sp | (m) | | ny |\ t | (pl | sh) | ts (70 | m\-| m3 | M5) | tx\-9 | up (\ .b | G1 | si) | utst | V400 | veri | vi (rg | te) | vk (40 | 5 [0-3] |\-v) | vm40 | voda | vx (52 | 53 | 60 | 70 | 80 | 81 | 85 | 98) | W3C (\-|) | webc | whit | wi (g | nc | nw) | wmlb wonu | x700 | yas\-| your | zeto | zte\-") {set $mobile_rewrite perform } location / {if ($mobile_rewrite = perform) {return 301 [http://kason995.com/m$request_uri](http://kason995.com/m$request_uri); # Mobile version} if ($mobile_rewrite = do_not_perform) {proxy_pass [http://172.168.1.93:8009](http://172.168.1.93:8009/); # computer version} proxy_http_version 1.1 Proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade;} location ^ / m / {proxy_pass [http://172.168.1.93:8090](http://172.168.1.93:8090/); proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection' upgrade' Proxy_set_header Host $host; proxy_cache_bypass $http_upgrade;}} server {listen 80; server_name kason995.com; set $mobile_rewrite do_not_perform; if ($http_user_agent ~ * "(android | bb\ d+ | meego). + mobile | avantgo | bada\ / | blackberry | blazer | compal | fennec | hiptop | iemobile | ip (hone | od | ad) | iris | kindle | lge | maemo | midp | mobile.+firefox | netfront | opera (ob) I | in (in)? | palm | p (palm | palm)\ / | os | os | phone (4 | 6) 0 | phone | |\. (| phone) | } if ($http_user_agent ~ * "^ (1207 | 6310 | 6590 | 3gso | 4thp | 50 [1-6] I | 770s | 802s | a wa | ac (er | oo | s\ -) | ai (ko | rn) | al (av | ca | co) | amoi | an (ex | ny | yw) | aptu | ar (ch | go) | as (te | us) | attw | au (di |\-m | r | s) | avan | be (ck | ll | nq) | nq (nq) | nq (nq) | bi (nq) | bi (bi |) | Jun (e | v) w | lb | lb\-(n | u) | C55\ /) | lb | lb\-/ lb | lb | lb\-rd | lb | | be\-Cun | | be | Lao | | Ic | K0) | esl8 | ez ([4-7] 0 | os | wa | ze) | fetc | fly (\-| _) | G1 u | G560 | gene | gf\-5 | g\-mo | go (\ .w | od) | gr (ad | un) | haie | hcit | hd\-(m | t) | hei\-| hi (pt | ta) | hp (I | ip) | hs\-c | ht (\-| | _ | a | g | p | s | t) | tp) | hu (aw | tc) | I\-(20 | go | ma) | i230 | iac (\-|\ /) | ibro idea | idea | ig01 | idea | ig01 | ig01 (t) | ikom (v) | | ikom | ikom (/ /) | im1k (I | ip) | | idea (/) | | ikom (/ /) | | idea (/ /) | 54 / u | | 54 |\ k | | libw | lynx | M1\-w | m3ga | M50\ / | ma (te | ui | xo) | mc (01 | 21 | ca) | m\-cr | me (rc) | mi (o8 | oa | ts) | mmef | mo (01 | 02 | bi | de | do | t (\-| o | v) | zz) | mt (50 | p1 | v) | mwbp | mywa | N10 [0-2] | N20 [2-3] | N30 (0 | 2) | N50 (0 | 2 | 5) | N7 (0 (0 | 1) | 10) | ne (c | m)\-| on tf wf | wg | wt) | nok (6) | nzph o2im | op (ti) | ti ti (ti) | wv | ti | ti (ti) | ti | wv (a d | t) | wv | 13 (\-c | 1 | 8) | owg1 | oran | 2 | oran | | | prox | psio | pt\-g | qa\-a | qc (07 | 12 | 21 | 32 |\-[2-7] | I\ -) | qtek | R380 | R600 | raks | rim9 | ro (ve | zo) | S55\ / | sa (ge | ma | mm | ms | ny | va) | sc (01 | h\-| oo | p\ -) | sdk\ / | se (c (\-| 0 | 1) | 47 | mc | nd | ri) | sgh\-| shar sie (\-m) | sk\-0 | sl (45 | id) | sm (al | ar | b3 | it | T2) | so (so) | ft (so) | so (so) | (01 | h\-v\-| v) | ft (ny) | 18 (50) | 18 | 50) | T6 (10) | 10) | 18) (ny) | sp\-sp | (m) | | ny |\ t | (pl | sh) | ts (70 | m\-| m3 | M5) | tx\-9 | up (\ .b | G1 | si) | utst | V400 | veri | vi (rg | te) | vk (40 | 5 [0-3] |\-v) | vm40 | voda | vx (52 | 53 | 60 | 70 | 80 | 81 | 85 | 98) | W3C (\-|) | webc | whit | wi (g | nc | nw) | wmlb wonu | x700 | yas\-| your | zeto | zte\-") {set $mobile_rewrite perform } location / {if ($mobile_rewrite = perform) {return 301 [http://kason995.com/m$request_uri](http://kason995.com/m$request_uri); # Mobile version} if ($mobile_rewrite = do_not_perform) {proxy_pass [http://172.168.1.93:8009](http://172.168.1.93:8009/); # computer version} proxy_http_version 1.1 Proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade;} location ^ / m / {proxy_pass [http://172.168.1.93:8090](http://172.168.1.93:8090/); proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection' upgrade' Proxy_set_header Host $host; proxy_cache_bypass $http_upgrade;}}
4, configure and view the soft connection
5. Modify the hosts file of ubuntu.
Make the domain name 995.com correspond to the IP address of the local windows computer or 127.0.0.1
C:\ Windows\ System32\ drivers\ etc
If the custom domain name cannot be resolved normally after reboot, it is recommended to configure the hosts file of the windows machine.
The catalogue is here.
C:\ Windows\ System32\ drivers\ etc
This is the hosts file in my windows:
# Copyright (c) 1993-2009 Microsoft Corp.## This is a sample HOSTS file used by Microsoft TCP/IP for Windows.## This file contains the mappings of IP addresses to host names. Each# entry should be kept on an individual line. The IP address should# be placed in the first column followed by the corresponding host name.# The IP address and the host name should be separated by at least one# space.## Additionally Comments (such as these) may be inserted on individual# lines or following the machine name denoted by a'# 'symbol.## For example:## 102.54.94.97 rhino.acme.com # source server# 38.25.63.10 x.acme.com # x client host# localhost name resolution is handled within DNS itself.# 127.0.0.1 localhost#:: 1 localhost172.168.1.117 kason995.com# the above line serves the custom domain name. 192.30.255.112 github.com git 185.31.16.184 github.global.ssl.fastly.net
6. Restart Nginx
Nginx-s reload
7. Use the custom domain name in Ubuntu to test and visit the PC station.
8. Use the custom domain name in Ubuntu to test and visit the mobile station.
This is the end of this article on "nginx configuring PC stations to separate mobile stations to achieve redirection". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.