赞
踩
同一个域名,手机端和电脑端请求的页面不一样,但是域名要求不变,现在有两个前端代码,分别跑在两个docker里面,一个为app1另外一个是app2,暴露的端口分别是8080,8081,通过nginx将请求反代到两个docker容器中,后端接口端口8082
nginx配置如下
配置一upstream.conf
upstream app1 {
server 127.0.0.1:8080 weight=10;
}
upstream app2 {
server 127.0.0.1:8081 weight=10;
}
upstream app3 {
server 127.0.0.1:8082 weight=10;
}
nginx配置二web.conf
server { listen 80; server_name domaincxom; location / { set $is_mobile http://app1; #设置一个初始值 if ( $http_user_agent ~ "(MIDP)|(WAP)|(UP.Browser)|(Smartphone)|(Obigo)|(Mobile)|(AU.Browser)|(wxd.Mms)|(WxdB.Browser)|(CLDC)|(UP.Link)|(KM.Browser)|(UCWEB)|(SEMC\-Browser)|(Mini)|(Symbian)|(Palm)|(Nokia)|(Panasonic)|(MOT\-)|(SonyEricsson)|(NEC\-)|(Alcatel)|(Ericsson)|(BENQ)|(BenQ)|(Amoisonic)|(Amoi\-)|(Capitel)|(PHILIPS)|(SAMSUNG)|(Lenovo)|(Mitsu)|(Motorola)|(SHARP)|(WAPPER)|(LG\-)|(LG/)|(EG900)|(CECT)|(Compal)|(kejian)|(Bird)|(BIRD)|(G900/V1.0)|(Arima)|(CTL)|(TDG)|(Daxian)|(DAXIAN)|(DBTEL)|(Eastcom)|(EASTCOM)|(PANTECH)|(Dopod)|(Haier)|(HAIER)|(KONKA)|(KEJIAN)|(LENOVO)|(Soutec)|(SOUTEC)|(SAGEM)|(SEC\-)|(SED\-)|(EMOL\-)|(INNO55)|(ZTE)|(iPhone)|(Android)|(Windows CE)|(Wget)|(Java)|(curl)|(Opera)" ) { set $is_mobile http://app2; } proxy_pass $is_mobile; proxy_http_version 1.1; proxy_set_header Connection ""; client_max_body_size 1000m; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Scheme $scheme; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_redirect off; } location /api/ { proxy_pass http://app3; proxy_http_version 1.1; proxy_set_header Connection ""; client_max_body_size 1000m; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Scheme $scheme; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_redirect off; } access_log /var/log/nginx/domain.com.access.log main; error_log /var/log/nginx/domain.com.error.log; }
这样就可以根据系统请求不同的页面,如果代码不放在容器,也可以把两个前端目录放在不同的文件夹,变量换成不同文件夹的路径
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。